QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108004 | #6409. Classical Data Structure Problem | whatever# | WA | 2ms | 5376kb | C++17 | 2.8kb | 2023-05-23 13:37:45 | 2023-05-23 13:37:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(y<x)x=y;}
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define mem(x) memset((x),0,sizeof(x))
typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef unsigned u32;
typedef unsigned uint;
typedef unsigned long long u64;
namespace orzjk{
const int SZ=1e6;
char buf[SZ],*p1=buf,*p2=buf;
char nc(){
return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
char fub[SZ],*p3=fub,*p4=fub+SZ;
void pc(char c){
p3==p4&&(fwrite(fub,1,SZ,stdout),p3=fub);
*p3++=c;
}
void flush(){
fwrite(fub,1,p3-fub,stdout),p3=fub;
}
}
using orzjk::nc;
using orzjk::pc;
//#define nc getchar
//#define pc putchar
int read(){
int x=0,f=1;char c=nc();
while(c<48)c=='-'&&(f=-1),c=nc();
while(c>47)x=x*10+(c^48),c=nc();
return x*f;
}
template<class T>void write(T x){
static char st[41];
if(!x)return pc(48),void();
char*p=st;
if(x<0)x=-x,pc('-');
for(;x;x/=10)*p++=x%10|48;
do{
pc(*--p);
}while(p!=st);
}
//const int P=1e9+7;
const int P=998244353;
int qp(int a,int k){
int res=1;for(;k;k>>=1,a=1ll*a*a%P)if(k&1)res=1ll*res*a%P;return res;
}
const int maxn=5e5+10;
#define mid ((l+r)/2)
int rt,tot;
struct node{
int ls,rs;
uint s0,s1;
}tr[maxn*60];
void add(int&k,int l,int r,int pos,uint v0,uint v1){
if(!k){
k=++tot;
}
tr[k].s0+=v0;
tr[k].s1+=v1;
if(l<r)pos<=mid?add(tr[k].ls,l,mid,pos,v0,v1):add(tr[k].rs,mid+1,r,pos,v0,v1);
}
node ask(int k,int l,int r,int pos){
if(!k)return{0,0,0,0};
if(r<=pos){
return tr[k];
}
if(pos<=mid){
return ask(tr[k].ls,l,mid,pos);
}else{
node o=ask(tr[k].rs,mid+1,r,pos);
o.s0+=tr[tr[k].ls].s0;
o.s1+=tr[tr[k].ls].s1;
return o;
}
}
#undef mid
void solve(){
uint n,m;
n=read(),m=read();
uint las=0;
for(uint i=1;i<=n;i++){
uint l=(read()+las)%(1<<m);
uint r=(read()+las)%(1<<m);
if(l>r)swap(l,r);
add(rt,0,(1<<m)-1,l,i,i*l);
if(r<(1u<<m)-1)add(rt,0,(1<<m)-1,r+1,-i,-i*(r+1));
node o=ask(rt,0,(1<<m)-1,r);
las+=o.s0*(r+1)-o.s1;
if(l>0){
o=ask(rt,0,(1<<m)-1,l-1);
las-=o.s0*l-o.s1;
}
// cout<<las<<endl;
}
cout<<las<<endl;
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// int T;cin>>T;while(T--)solve();
solve();
orzjk::flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3376kb
input:
5 2 2 1 1 3 3 2 1 0 0 2
output:
87
result:
ok 1 number(s): "87"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5376kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3372kb
input:
1 2 3 1
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3452kb
input:
1 5 31 15
output:
17
result:
ok 1 number(s): "17"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
1 20 366738 218765
output:
147974
result:
ok 1 number(s): "147974"
Test #6:
score: 0
Accepted
time: 2ms
memory: 3376kb
input:
1 30 86669484 41969116
output:
44700369
result:
ok 1 number(s): "44700369"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3344kb
input:
10 5 20 31 2 2 14 18 13 25 26 4 22 9 15 9 19 16 15 27 9 20
output:
1414
result:
ok 1 number(s): "1414"
Test #8:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
100 10 245 987 817 813 743 560 548 504 116 479 223 199 775 998 126 542 791 823 96 318 69 349 0 584 245 601 119 513 93 820 115 307 838 978 249 767 433 287 240 8 22 683 169 720 395 592 903 866 919 652 510 563 858 345 938 250 550 239 981 7 784 926 212 644 272 365 490 871 470 987 571 53 65 593 515 370 1...
output:
20383734
result:
ok 1 number(s): "20383734"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3460kb
input:
1000 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 1 1 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 1 1 1 1 1...
output:
190098735
result:
ok 1 number(s): "190098735"
Test #10:
score: 0
Accepted
time: 2ms
memory: 3376kb
input:
1000 5 8 18 31 28 19 3 15 28 5 22 19 1 26 27 17 17 5 26 6 27 10 6 5 2 3 19 6 6 28 16 17 16 0 21 7 31 13 25 13 10 28 30 0 13 21 5 2 9 25 28 4 18 31 13 1 26 30 3 5 8 19 16 22 10 15 17 3 25 6 27 18 26 27 1 26 29 18 21 14 20 5 1 26 9 7 13 19 25 15 11 24 17 12 28 24 17 4 27 20 27 31 18 25 17 1 28 5 0 16 ...
output:
794181769
result:
ok 1 number(s): "794181769"
Test #11:
score: -100
Wrong Answer
time: 1ms
memory: 3412kb
input:
1000 10 732 399 190 578 491 867 330 55 113 400 34 734 790 927 201 156 107 359 790 398 401 523 634 505 570 305 281 513 551 35 610 33 231 330 833 756 213 444 412 315 139 165 533 21 35 977 319 884 894 72 149 667 16 538 282 860 850 550 100 99 801 138 159 34 468 852 840 853 368 994 469 906 393 298 464 89...
output:
3976408120
result:
wrong answer 1st numbers differ - expected: '755182648', found: '3976408120'