QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385279#7765. Xor Mastervaleriu#10 73ms3664kbC++203.5kb2024-04-10 17:12:212024-07-04 03:34:15

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 03:34:15]
  • 评测
  • 测评结果:10
  • 用时:73ms
  • 内存:3664kb
  • [2024-04-10 17:12:21]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int bmax = 64;

namespace Basis {
   ull pivot[bmax];
   ull contrmsk[bmax];
   ull control = 0;
   ull flippers = 0;
   
   bool add(ull x) {
      for(int i = bmax - 1; i >= 0; i--) {
         if(pivot[i] == 0 && ((1ull << i) & x)) {
            pivot[i] = x;
            break;
         }
         else if(pivot[i] != 0 && ((1ull << i) & x))
            x ^= pivot[i];
      }
      if(x == 0) return 0;
      for(int i = 0; i < bmax; i++) {
         if(pivot[i] == 0) continue;
         for(int j = i + 1; j < bmax; j++) {
            if(pivot[j] & (1ull << i))
               pivot[j] ^= pivot[i];
         }
      }
      
      control = 0;
      flippers = 0;
      for(int poz = 0; poz < bmax; poz++) {
         contrmsk[poz] = 0;
         if(pivot[poz] != 0) {
            control |= (1ull << poz);
            continue;
         }
         for(int i = poz + 1; i < bmax; i++)
            if(pivot[i] & (1ull << poz)) contrmsk[poz] |= (1ull << i);
            
         if(__builtin_popcountll(contrmsk[poz]) % 2 == 1)
            flippers |= (1ull << poz);
      }
      
      return 1;
   }
   
   ull get_val(ull a) {
      //cerr << a << '\n';
      //ull tmp = a;
      ull R = 0;
      //for(int i = bmax - 1; i >= 0; i--) {
         //if(pivot[i] != 0) {
            //if(!(a & (1ull << i)))
               //a ^= pivot[i];
         //}
      //}
      //swap(tmp, a);
      for(int i = 0; i < bmax; i++) {
         if(pivot[i] != 0) continue;
         R |= ((ull)((__builtin_popcountll(a & contrmsk[i]) & 1) 
                  ^ (__builtin_popcountll(contrmsk[i]) & 1)
                  ^ ((a & (1ull << i))? 1 : 0))) << i;
      }
      
      //if(tmp != (R | Basis::control)) {
         //for(int i = 0; i < bmax; i++) cout << bitset<32>(pivot[i]) << '\n';
         //cout << "--\n";
         //cout << bitset<32>(tmp) << '\n' << bitset<32>(R | Basis::control) << '\n';
         //exit(0);
      //}
      
      return R | Basis::control;
   }
}

signed main() {
   cin.tie(0) -> sync_with_stdio(0);
   int n, q;
   cin >> n >> q;
   
   vector<ull> v(n + 1), real(n + 1);
   for(auto &x : v | views::drop(1)) cin >> x;
   real = v;
   
   auto update = [&](int p, ull x) {
     v[p] ^= Basis::get_val(x);
     real[p] ^= x;
   };
   
   auto reformat = [&]() {
      for(int i = 1; i <= n; i++) v[i] = Basis::get_val(real[i]);
      return;
   };
   
   auto query = [&](int l, int r) -> ull {
      ull rez = 0, part = 0;
      for(int i = l; i <= r; i++)
         part ^= real[i],
         rez += Basis::get_val(part);
      return rez;
   };
   
   vector<ull> results;
   
   for(int i = 0; i < q; i++) {
      int T;
      cin >> T;
      if(T == 1) {
         int p; 
         ull x;
         cin >> p >> x;
         update(p, x); 
      }
      
      else if(T == 2) {
         ull x;
         cin >> x;
         if(Basis::add(x)) {
            reformat();
         }
      }
      
      else {
         int l, r;
         cin >> l >> r;
         results.emplace_back(query(l, r)); // + Basis::control * (ull)(r - l + 1)
      }
   }
   
   for(auto x : results) cout << x << '\n';
   
}

/**
  Anul asta nu se da centroid
  -- Rugaciunile mele
*/


詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 71ms
memory: 3588kb

input:

2000 2000
1860495733 462603674 3739839441 759356520 47330263 550811730 2301200895 989240351 2499503801 2624225494 2123076812 1180966826 238739434 488666688 784742950 2583466952 4111371941 2335988605 2583741355 933716686 1644403538 1970423306 304500250 905101643 1814942168 1136358764 88729799 1577263...

output:

867006634793
3418049036989
1658469159497
794670034691
239792547603
1587489101990
592222190840
1343829229567
971235609706
571701308760
1219913933321
588622962923
2129364200509
1007100395808
3134493164996
3145027621038
2599298085956
1729302186341
837940435945
242569415869
2908005634977
1692554597386
1...

result:

ok 1001 lines

Test #2:

score: 0
Accepted
time: 73ms
memory: 3580kb

input:

2000 2000
836488286 497338588 1858847699 3099907357 1601878363 409027819 646677017 3314413779 3312383261 4245381929 661740170 2016795844 1226219370 1347593623 4008424282 2941543248 1331853899 3217984002 3651447350 1223595274 1733763258 2829453991 3934056384 2556266950 326379115 3240694642 2405972228...

output:

1042755994488
3566460727022
4896344756993
181148455339
5392308096517
128329799686
3895218239827
646945360393
2802192775672
4115818631146
377318752396
3776679332329
1298148822697
1295992748696
1351097540228
3413899110602
2303816407066
1713972222254
3490230048186
359123029421
2753519321710
37163510035...

result:

ok 987 lines

Test #3:

score: 0
Accepted
time: 72ms
memory: 3592kb

input:

2000 2000
934565373 583361217 1928523866 3968138916 58091196 1055428888 754057714 2583245062 1561553117 3803231337 1941815547 3183481079 4033721998 1961504708 1274020496 1413365247 4225380350 910888832 2085306570 4120303112 2310986051 3150392885 1863228247 2487640801 2753501595 1392599097 2663527219...

output:

3557365099431
1521170947970
1408454872311
2097066041438
1547787649380
1699033926121
731607397173
1512504400312
2238024031105
1226691488018
2720868465776
16740827185
1239458195766
34177580110
723038300762
89948012428
1059039811258
999014326614
20524953249
2755015662939
3285388608412
1592295267345
593...

result:

ok 1024 lines

Test #4:

score: 0
Accepted
time: 70ms
memory: 3664kb

input:

2000 2000
3045151729 428960501 1820713794 2282572198 2207348805 3422275025 782655334 2676169210 3422244596 3935592456 3633929583 3812985947 3297835714 1994436805 1574888855 3231965757 2375331974 982931142 234068847 2950645216 1927175875 202726997 3573353370 148578451 1270283373 2390862707 3593433616...

output:

445704627329
4223618535024
2450863577199
179382947501
2163925703050
2473211169137
1406440975573
1486681378298
5485708409222
3247499164866
170969938085
1264328439756
3972780905954
5127064167621
3233154054862
2628294443523
3887884373918
3201286978615
4072438879416
4508920381717
2500182546199
147588087...

result:

ok 975 lines

Subtask #2:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded

input:

500000 100000
12261386944926786495 7846697792998647383 16622924885320463714 170129022271213944 12625257523700625864 7684671687986103560 11532026873918423068 1131776055566669037 8263146651412710501 17872572061246021001 5017109039248728310 11088626167542318645 13810119722795416818 10928315716094262229...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

100000 100000
860905160 3192911636 290327446 2020707113 959258245 454185039 421895589 1070265496 2218913641 1684685660 1206723673 2606734467 4247254571 3341954386 3805299640 1702270353 2472053741 2816060613 1307901348 2702949728 879391505 884661815 330738731 1575749344 1239158446 2099693858 67466644...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%