QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360481 | #5441. Quartz Collection | qwqUwU_ | WA | 2ms | 5920kb | C++14 | 3.2kb | 2024-03-21 20:09:55 | 2024-03-21 20:09:56 |
Judging History
answer
// clang-format off
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define st first
#define nd second
#define bit(s,x) (((s)>>(x))&1)
#define ctz(s) __builtin_popcount(s)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 i128;
typedef long double ld;
typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; typedef pair<int,ll> pil;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
inline void write(ll x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
// remember to change!!!
const int mod=998244353;
inline void plust(int &x,int y,int p=mod){x=x+y<p?x+y:x+y-p;}
inline void mul(int &x,int y,int p=mod){x=1ll*x*y%p;}
inline int fp(int x,ll p=mod-2,int m=mod,int res=1){
for(;p;p>>=1){if(p&1)mul(res,x,m);mul(x,x,m);}
return res;
}
const int N=1e5+10;
const int INF=0x3fffffff;
// clang-format on
pii a[N];
struct info1{ll a[2];int siz;}t[1<<18];
info1 operator +(info1 A,info1 B){
info1 res;res.siz = A.siz + B.siz;
for(int i=0;i<2;++i)res.a[i] = A.a[i] + B.a[(i+A.siz)%2];
return res;
}
struct info2{ll a[4];int siz;}p[1<<18];
info2 operator +(info2 A,info2 B){
info2 res;res.siz = A.siz + B.siz;
for(int i=0;i<4;++i)res.a[i] = A.a[i] + B.a[(i+A.siz)%4];
return res;
}
#define mid ((l+r)>>1)
inline void update1(int x,int l,int r,int nx,info1 k,int op){
if(l==r){
ll s = t[x].a[0] + t[x].a[1]+op*k.a[0]+op*k.a[1],d=nx;
int sz = t[x].siz + op;
t[x] = {{(s + (sz&1)*d)>>1,(s - (sz&1)*d)>>1},sz};
return ;
}
if(nx<=mid)update1(x<<1,l,mid,nx,k,op);
else update1(x<<1|1,mid+1,r,nx,k,op);
t[x] = t[x<<1] + t[x<<1|1];
}
inline void update2(int x,int l,int r,int nx,info2 k,int op){
if(l==r){
ll s = p[x].a[0] + p[x].a[2] +op*k.a[0] + op*k.a[2],d=nx;
int sz = p[x].siz + op;
if(sz%4==1)p[x] = {{(s-d)>>1,(s+d)>>1,(s+d)>>1,(s-d)>>1},sz};
if(sz%4==2)p[x] = {{s>>1,(s+2*d)>>1,s>>1,(s-2*d)>>1},sz};
if(sz%4==3)p[x] = {{(s+d)>>1,(s+d)>>1,(s-d)>>1,(s-d)>>1},sz};
if(sz%4==0)p[x] = {{s>>1,s>>1,s>>1,s>>1},sz};
return ;
}
if(nx<=mid)update2(x<<1,l,mid,nx,k,op);
else update2(x<<1|1,mid+1,r,nx,k,op);
p[x] = p[x<<1|1] + p[x<<1];
}
int main() {
//freopen("data.in", "r", stdin);
// freopen(".in","r",stdin);
// freopen("myans.out","w",stdout);
int n=read(),T=read();
for(int i=1;i<=n;++i){
a[i].st=read(),a[i].nd=read();
if(a[i].st >= a[i].nd)update1(1,0,n,a[i].st-a[i].nd,{{a[i].st,a[i].nd},1},1);
else update2(1,0,n,a[i].nd-a[i].st,{{a[i].st,a[i].nd,a[i].nd,a[i].st},1},1);
}
int s=p[1].siz;
printf("%lld\n",p[1].a[0] + t[1].a[s&1]);
while(T--){
int i=read();
if(a[i].st >= a[i].nd)update1(1,0,n,a[i].st-a[i].nd,{{a[i].st,a[i].nd},1},-1);
else update2(1,0,n,a[i].nd-a[i].st,{{a[i].st,a[i].nd,a[i].nd,a[i].st},1},-1);
a[i].st=read(),a[i].nd=read();
if(a[i].st >= a[i].nd)update1(1,0,n,a[i].st-a[i].nd,{{a[i].st,a[i].nd},1},1);
else update2(1,0,n,a[i].nd-a[i].st,{{a[i].st,a[i].nd,a[i].nd,a[i].st},1},1);
s=p[1].siz;
printf("%lld\n",p[1].a[0] + t[1].a[s&1]);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5916kb
input:
4 5 2 4 5 7 1 7 2 1 4 5 2 1 6 2 4 4 3 2 1 3 3 6 6
output:
13 14 15 14 10 13
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 5920kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
100 100 6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55...
output:
5109 5065 5060 5007 4975 4993 4950 4928 4922 4930 4948 4915 4885 4863 4898 4864 4837 4787 4793 4774 4730 4708 4659 4617 4546 4618 4654 4687 4677 4685 4714 4733 4728 4701 4660 4631 4628 4682 4743 4777 4764 4772 4754 4759 4715 4744 4672 4687 4700 4649 4611 4543 4523 4554 4605 4585 4532 4520 4489 4505 ...
result:
ok 101 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3992kb
input:
1000 1000 411 789 753 186 495 203 417 324 490 424 195 480 314 23 663 218 12 747 124 390 134 38 218 536 291 840 174 908 474 767 313 167 575 9 857 427 313 27 959 935 258 70 472 957 747 228 205 939 293 303 626 802 712 283 658 346 208 383 889 204 99 640 801 966 828 742 534 11 259 734 226 129 843 350 50 ...
output:
490601 490340 490353 490689 490697 490600 490571 491078 491388 491507 491729 491809 491984 492228 492161 492171 492384 492276 492693 492547 492372 492580 492350 492795 492635 492941 492936 492797 492359 492108 492670 492589 492570 492700 492910 492401 492274 492263 491905 491692 492032 492168 492350...
result:
ok 1001 numbers
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 4824kb
input:
5000 1000 72520 61541 4609 95655 27768 67682 48763 4836 63868 3082 44496 5022 70138 88832 25864 48681 5212 79532 1134 60190 84561 98392 91027 55707 72938 83316 60044 93249 82269 88819 83951 6069 35302 29132 1882 68479 3489 45817 79436 37261 88849 763 23786 62641 89532 32244 85372 46815 6765 56651 27...
output:
249472991 249485857 249499614 249450407 249443417 249465722 249420912 249439678 249474867 249452978 249499236 249522663 249560782 249522780 249497790 249511710 249525746 249534822 249546855 249497456 249556837 249517741 249476883 249450095 249406120 249401504 249373151 249411586 249443710 249420346 ...
result:
wrong answer 1st numbers differ - expected: '249456797', found: '249472991'