Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<vector>
  6. #include<stack>
  7. #include<queue>
  8. #include<set>
  9. #include<map>
  10. #include<unordered_map>
  11. #define x first
  12. #define y second
  13. #define all(x) x.begin(), x.end()
  14. #define pb push_back
  15. #define mp make_pair
  16. #define pii pair<char,int>
  17. // #define int long long
  18. using namespace std;
  19. string pp(int a){
  20. if(a == 0){
  21. return "0";
  22. }
  23. if(a == 1){
  24. return "1";
  25. }
  26. return "2";
  27. }
  28. string bn(int a){
  29. if(a < 2){
  30. return pp(a);
  31. }else{
  32. return bn(a / 2) + pp(a % 2);
  33. }
  34. }
  35. int f(int a,int b){
  36. string p = bn(a),q = bn(b);
  37. while(p.size() < q.size()){
  38. p = "0" + p;
  39. }
  40. while(q.size() < p.size()){
  41. q = "0" + q;
  42. }
  43. // cout << p << ' ' << q << endl;
  44. for(int i = 0;i < p.size();i++){
  45. if(p[i] > q[i]){
  46. return (p.size() - i - 1);
  47. }
  48. if(p[i] < q[i]){
  49. break;
  50. }
  51. }
  52. return -1;
  53. }
  54. signed main(){
  55. ios_base::sync_with_stdio(false);
  56. cin.tie(0);
  57. cout.tie(0);
  58. int n,q;
  59. cin >> n;
  60. vector<int>a(n);
  61. for(int i = 0;i < n;i++){
  62. cin >> a[i];
  63. }
  64. cin >> q;
  65. int p,x;
  66. int cnt = 0;
  67. q++;
  68. vector<int>ans;
  69. while(q--){
  70. if(cnt != 0){
  71. cin >> p >> x;
  72. a[p - 1] = x;
  73. }
  74. cnt++;
  75. int b = 0;
  76. for(int i = 0;i < n - 1;i++){
  77. int kk = f(a[i] ^ b,a[i + 1] ^ b);
  78. if(kk != -1){
  79. b |= (1 << kk);
  80. }
  81. }
  82. // cout << b << endl;
  83. bool ok = 1;
  84. for(int i = 0;i < n - 1;i++){
  85. if((a[i + 1] ^ b) < (a[i] ^ b)){
  86. ok = 0;
  87. break;
  88. }
  89. }
  90. if(ok){
  91. cout << b << endl;
  92. }else{
  93. cout << -1 << endl;
  94. }
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement