QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385359#7765. Xor Mastervaleriu#20 1328ms191084kbC++205.7kb2024-04-10 17:59:332024-07-04 03:34:44

Judging History

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

  • [2024-07-04 03:34:44]
  • 评测
  • 测评结果:20
  • 用时:1328ms
  • 内存:191084kb
  • [2024-04-10 17:59:33]
  • 提交

answer

#pragma GCC optimize("Ofast")
#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 contra = 0; contra < bmax; contra++) {
         contrmsk[contra] = 0;
         if(pivot[contra] != 0) {
            control |= (1ull << contra);
            continue;
         }
         for(int i = contra + 1; i < bmax; i++)
            if(pivot[i] & (1ull << contra)) contrmsk[contra] |= (1ull << i);
            
         if(__builtin_popcountll(contrmsk[contra]) % 2 == 1)
            flippers |= (1ull << contra);
      }
      
      return 1;
   }
   
   ull get_val(ull a) {
      ull R = 0;
      for(int i = 0; i < bmax; i++) {
         if(pivot[i] != 0) continue;
         R |= ((ull)((__builtin_popcountll(a & contrmsk[i]) & 1) 
                  ^ ((a & (1ull << i))? 1 : 0))) << i;
      }
      return R;
   }
}

pii operator +(const pii& x, const pii& y) {
   return pii{x.first + y.first, x.second + y.second};
}

pii flip(const pii& x) { return pii{x.second, x.first}; }

struct Node {
   int cnt[bmax], len;
   ull txor;
   Node() {
      for(int i = 0; i < bmax; i++) cnt[i] = 0;
      len = 1;
      txor = 0;
   }
   Node(ull a) {
      for(int i = 0; i < bmax; i++) cnt[i] = 0;
      len = 0;
      txor = a;
   }
   
   void pull(const Node L, const Node R) {
      for(int i = 0; i < bmax; i++) cnt[i] = L.cnt[i] + ((L.txor & (1ull << i))? R.len - R.cnt[i] : R.cnt[i]);
      txor = L.txor ^ R.txor;
      len = L.len + R.len;
   }
};

template<typename Node>
struct AINT {
   vector<Node> aint;
   int n;
   void init(int n_, Node TMP = Node()) {
      n = n_;
      aint.assign(2 * n + 5, TMP);
   }
   template<class CB> void walk(CB&& cb) { walk(cb, 1, n); }
   template<class CB> void walk(CB&& cb, int l, int r) { walk(cb, l, r, 1, 1, n); }
   template<class CB> void walk(CB&& cb, int l, int r, int node, int cl, int cr) { 
      if(cr < l || r < cl) return;
      if(l <= cl && cr <= r && !cb(aint[node], cl, cr)) return;
      
      int mid = (cl + cr) >> 1, L = node + 1, R = node + (mid - cl + 1) * 2;
      walk(cb, l, r, L, cl, mid);
      walk(cb, l, r, R, mid + 1, cr);
      
      aint[node].pull(aint[L], aint[R]);
   }
};

const int nmax = 5e5 + 5;
const int Jump = 1000;
Node sage[nmax];
bool issage[nmax];

signed main() {
   cin.tie(0) -> sync_with_stdio(0);
   int n, q;
   cin >> n >> q;
   
   AINT<Node> aint;
   aint.init(n);
   
   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;
      
      while(p >= 0 && issage[p] == 0) p--;
      if(p == -1) return;
      Node val(0);
      for(int i = p + Jump - 1; i >= p; i--) {
         Node here;
         here.pull(Node(v[i]), Node());
         val.pull(here, val);
      }
      sage[p] = val;
         
      
      //aint.walk([&](Node& val, int cl, int cr) {
         //val.pull(Node(v[cl]), Node());
         //return 0;
      //}, p, p);
   };
   
   auto reformat = [&]() {
      for(int i = 1; i <= n; i++) v[i] = Basis::get_val(real[i]);
      
      Node val(0);
      int timer = 0;
      for(int i = n; i > 0; i--) {
         Node here;
         here.pull(Node(v[i]), Node());
         val.pull(here, val);
         timer++;
         if(timer == Jump) {
            issage[i] = 1;
            sage[i] = val;
            val = Node(0);
            timer = 0;
         }
         
         else
            issage[i] = 0;
      }
      
      //aint.walk([&](Node& val, int cl, int cr) {
         //if(cl != cr) return 1;
         //val.pull(Node(v[cl]), Node());
         //return 0;
      //});
      return;
   };
   
   auto query = [&](int l, int r) -> ull {
      ull rez = 0;
      ull part = Basis::flippers;
      while(l <= r) {
         if(issage[l] && l + Jump - 1 <= r) {
            for(int i = 0; i < bmax; i++) 
               rez += (1ull << i) * ((part & (1ull << i))? sage[l].len - sage[l].cnt[i] : sage[l].cnt[i]);
            part ^= sage[l].txor;
            l += Jump;
            continue;
         }
         part ^= v[l];
         rez += part;
         l++;
      }
      return rez;
   };
   
   reformat();
   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;
         cout << query(l, r) + Basis::control * (ull)(r - l + 1) << '\n';
      }
   }
   
}

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

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 307ms
memory: 136968kb

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: 305ms
memory: 136980kb

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: 288ms
memory: 136964kb

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: 307ms
memory: 137000kb

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:

12337138966997790840
11593856511006775316
5653988472748567965
6281173414355612100
18027435777450732541
2903343914316621940
9422461876307420631
76690753587353877
798850376670823348
10137130634921141648
13914431888234873359
10192090671035653185
11569745711967074397
12303071505845046803
637460082558284...

result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 10
Accepted

Test #15:

score: 10
Accepted
time: 1310ms
memory: 190892kb

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:

208755389215975
125497785366837
162446748431411
63166834945113
33018804920229
89343160639243
36805816758195
40790494641758
13928126471189
267168502433672
191989403472418
276350936750564
11189666657474
133862444125402
92684260245650
179275392898572
46159208957881
232612971657325
184946588056252
11022...

result:

ok 49937 lines

Test #16:

score: 0
Accepted
time: 1324ms
memory: 190960kb

input:

100000 100000
3000426759 1824979832 10575943 1641880522 143940604 1261846884 1440252673 1935901636 2652482829 470200294 2760667036 1220768939 3242608584 30882643 3358811662 1954487430 4180122469 4037250966 1441428251 65645189 4256227499 2434976018 1044356540 1620226231 1790468792 103643592 177914654...

output:

145524055862860
161441138955842
306257129346343
299241569554302
226683771328975
181478349880992
130902872439424
280739831883457
4613950888066
230458529036600
79448487784419
221626929814178
372553919558010
197240289390578
161723969896905
318321608389202
174341260990323
316468299413037
71567183240652
...

result:

ok 49939 lines

Test #17:

score: 0
Accepted
time: 1317ms
memory: 190732kb

input:

100000 100000
498518053 2395903916 3150345345 970832874 3209063924 918965752 719268408 671515184 3219866836 2211624912 4145355509 2996354339 4177997608 3629522427 1213935750 2323829632 3165425771 298491930 908110837 335150507 2730640728 1723129376 652211552 542768976 2794794671 3614541766 2502995608...

output:

260888209253328
220417527912855
82382666528415
205546503607350
135868918784651
83987999793156
230878751182064
61087943195861
228413465926535
283578798581409
21723069972011
139237220178662
110232569033326
176416307293587
344477122018860
268362176646883
115160165700192
374561042493460
322099679993279
...

result:

ok 50165 lines

Test #18:

score: 0
Accepted
time: 1326ms
memory: 191084kb

input:

100000 100000
3992377736 434272953 2992624759 2250120461 2826429649 1076646810 1973468088 793827622 2495303276 3051008910 461259433 807863154 899742425 2917748831 3777743530 2401888492 375547402 445106376 3978593719 1459330010 3512989180 138941241 257638089 2598569114 2184509605 2499713476 239125335...

output:

147448496111215
217893531933388
149751201282482
207237624790060
236297842537499
215103721410855
77304922769081
222323379784810
186478109354540
112876203505747
179420115108834
150190314932342
43670232007873
25887688561684
46014605520682
21167146272975
216254665421226
136814646622945
4186313114826
229...

result:

ok 50066 lines

Test #19:

score: 0
Accepted
time: 1312ms
memory: 190888kb

input:

100000 100000
3179037198 1726433634 1170347124 1038182581 976465227 3428516821 2779258891 2172100746 2976741309 804773686 1819799408 2161144533 271279535 375735337 1495976758 1446095086 783591841 647495961 2978211107 4184592567 2538879833 1516802478 3667793825 3117167846 1421032731 399321258 2739042...

output:

14881117655388
285727776113744
96063693786679
42810374617026
288595074947863
280315397686375
289641204087564
112743323666062
186419939913803
111073514966384
130685514549648
254506212148884
101643204416767
253148324245449
95367927417
281948636745321
193523757014667
134607728490831
291309237374936
238...

result:

ok 50035 lines

Test #20:

score: 0
Accepted
time: 1324ms
memory: 190748kb

input:

100000 100000
2837558084 270944129 1488717152 2392454072 470770792 2777133 722770864 3585689195 590024623 3488355822 17552172 1874212154 4168915873 1921182598 4147474167 2573985631 3517994287 748095291 1037232836 3370419592 1671928653 4030684268 641958463 1580906861 2996601090 3022839831 4219465735 ...

output:

48146023505073
199293116412251
16853038897970
261946024338866
293982581313722
20413002833952
275337254322097
23734082669358
304448299364826
207480800390891
209702100347470
107059294321865
67809987007145
31022679709752
231784403945102
191992113958559
71931140153873
318909802436554
308235637561914
480...

result:

ok 50340 lines

Test #21:

score: 0
Accepted
time: 1328ms
memory: 191024kb

input:

100000 100000
364926614 1655853438 3186329604 2743661979 2747155766 1720061739 2439752943 937515084 2541570348 1831323174 2685307250 345381411 2570490374 1411159104 3124296940 1010675903 916623261 3920607778 1055185260 3605823397 3735681762 875120207 184660308 3070923245 4194650139 390860276 3773763...

output:

212343579500935
145743539929651
81469645915718
179691739954130
40183110135676
187234010931784
221570315189145
151009623141265
87859127080109
119598166244021
219492663052409
11708497011473
93783594707846
3576360455299
302012818573840
296265045459927
161349572929071
8052465444694
313371100072835
29316...

result:

ok 50029 lines

Subtask #5:

score: 0
Time Limit Exceeded

Dependency #4:

100%
Accepted

Test #22:

score: 0
Time Limit Exceeded

input:

500000 100000
17875507896876852594 1231709150845899221 4118660995540143087 2819399476387881514 10658483116489758483 1552311792717328959 14473006677868328329 994640445028619787 3867235579009926064 13154180381468776383 13818624943002555745 15236156474893022124 8540629523994518030 18015042213820785602 ...

output:

10869073095452935323
4937957831895612347
8597855937100549826
4077084800767531060
13112867824279445332
5105048791714899665
17718481205510838851
12074525849086176152
6525859617975446449
2082310637126089892
9399666547046514786
16816388302879441034
17588209628777971111
1847567427746727327
84872524510475...

result:


Subtask #6:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #4:

100%
Accepted

Test #28:

score: 0
Time Limit Exceeded

input:

100000 100000
1246217479 2497476349 1583301214 3092195131 1122763035 3685427378 3759274674 2212252942 3411779388 1407177641 3728104468 2189005231 2284116456 4163693736 2268105236 3484999142 3179046583 126949827 1675745535 2063659275 3494152722 1162732726 818211479 529059683 832000919 541445158 20214...

output:

21118991183514
49768407513437
16283715327990
30300194886183
130226443936196
9963088487267
94359773501533
31212763209891
114669734539010
25987252046404
255638314480251
18480623837996
234730518803626
270385386179776
21288562167432
17771165511946
187066248697012
130055797757555
125671783821257
23982825...

result:


Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%