QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385315#7765. Xor Mastervaleriu#0 1537ms518716kbC++204.7kb2024-04-10 17:36:192024-07-04 03:34:29

Judging History

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

  • [2024-07-04 03:34:29]
  • 评测
  • 测评结果:0
  • 用时:1537ms
  • 内存:518716kb
  • [2024-04-10 17:36:19]
  • 提交

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 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 {
   pii cnt[bmax];
   ull txor;
   Node() {
      for(int i = 0; i < bmax; i++) cnt[i].first = 1, cnt[i].second = 0;
      txor = 0;
   }
   Node(ull a) {
      for(int i = 0; i < bmax; i++) cnt[i] = pii{0, 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))? flip(R.cnt[i]) : R.cnt[i]);
      txor = L.txor ^ R.txor;
   }
};

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]);
   }
};

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;
      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]);
      
      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;
      Node elem(Basis::flippers);
      //elem.txor = Basis::flippers;
      aint.walk([&](Node& val, int cl, int cr) {
         elem.pull(elem, val);
         return 0;
      });
      
      for(int i = 0; i < bmax; i++)
         rez += elem.cnt[i].second * (1ull << i);
      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: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 5148kb

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:

4269592872226
4370386827587
4387466372345
4387466372345
4268681019395
4268681019395
4268681019395
4268681019395
4323970049885
4323970049885
4323970049885
4323970049885
4323970049885
4354701906035
4433870789657
4433870789657
4433870789657
4433870789657
4284851813589
4284851813589
4284851813589
428485...

result:

wrong answer 1st lines differ - expected: '867006634793', found: '4269592872226'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 471ms
memory: 518716kb

input:

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

output:

3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
3784313197144032250
...

result:

wrong answer 1st lines differ - expected: '12337138966997790840', found: '3784313197144032250'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 1537ms
memory: 106164kb

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:

244260980302513
211014712206001
225698131649201
185991158997681
173960955601585
196457994298033
175466341638833
177051184571057
166337388651185
267752303927985
238707031871587
284849476145251
140145585492067
207150296535139
184571116589155
231783007719523
159165311291491
260893222309987
234864109883...

result:

wrong answer 1st lines differ - expected: '208755389215975', found: '244260980302513'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%