QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21793 | #2831. Game Theory | s8194272# | AC ✓ | 263ms | 26116kb | C++14 | 2.7kb | 2022-03-08 15:42:27 | 2022-05-08 04:04:43 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define int long long
#define fi first
#define se second
#define max Max
#define min Min
#define abs Abs
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define fan(x) (((x-1)^1)+1)
#define mp(x,y) make_pair(x,y)
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
#define INF 0x3f3f3f3f
using namespace std;
inline int read()
{
int ans=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
return ans*f;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x/10) write(x/10);
putchar((char)(x%10)+'0');
}
template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a<b?a:b;}
template<typename T,typename TT> inline T Max(T a,TT b){return a<b?b:a;}
const int N=2e5+5,mod=998244353;
int n,q;
char s[N];
struct Node
{
int v1[2],v2[2];
Node operator + (const Node &x)const
{
Node res;
res.v1[0]=v1[0]+x.v1[0];
res.v1[1]=v1[1]+x.v1[1];
res.v2[0]=v2[0]+x.v2[0];
res.v2[1]=v2[1]+x.v2[1];
return res;
}
}zr;
struct Seg
{
Node val[N<<2];
int tg[N<<2];
void build(int x,int l,int r)
{
tg[x]=0;
if(l==r)
{
val[x]=zr;
val[x].v1[s[l]-'0']=1;
val[x].v2[s[l]-'0']=l;
return;
}
build(lc,l,mid);
build(rc,mid+1,r);
val[x]=val[lc]+val[rc];
}
void upd(int x)
{
tg[x]^=1;
swap(val[x].v1[0],val[x].v1[1]);
swap(val[x].v2[0],val[x].v2[1]);
}
void pushdown(int x)
{
if(tg[x])
{
upd(lc),upd(rc);
tg[x]=0;
}
}
void update(int x,int l,int r,int L,int R)
{
if(L<=l&&r<=R) return upd(x);
pushdown(x);
if(L<=mid) update(lc,l,mid,L,R);
if(mid+1<=R) update(rc,mid+1,r,L,R);
val[x]=val[lc]+val[rc];
}
Node query(int x,int l,int r,int L,int R)
{
if(L>R) return zr;
if(L<=l&&r<=R) return val[x];
pushdown(x);
if(L<=mid&&mid+1<=R)
return query(lc,l,mid,L,R)+query(rc,mid+1,r,L,R);
else if(L<=mid) return query(lc,l,mid,L,R);
else return query(rc,mid+1,r,L,R);
}
}sum;
signed main()
{
while(scanf("%lld%lld",&n,&q)!=EOF)
{
scanf("%s",s+1);
sum.build(1,1,n);
while(q--)
{
int l=read(),r=read();
sum.update(1,1,n,l,r);
Node t1=sum.query(1,1,n,1,n);
Node t2=sum.query(1,1,n,1,t1.v1[1]);
Node t3=sum.query(1,1,n,t1.v1[1]+1,n);
int ans=(t3.v2[1]-t2.v2[0])*2+t1.v1[1];
write(ans%mod);puts("");
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5736kb
input:
3 2 010 1 2 2 3 5 1 00000 1 5
output:
1 3 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 5812kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 9ms
memory: 5860kb
input:
2 2 01 2 2 2 2 2 2 01 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 00 1 2 1 2 2 2 11 1 2 1 2 2 2 01 2 2 1 1 2 2 10 2 2 1 2 2 2 01 1 2 1 2 1 2 0 1 1 1 1 2 2 01 1 2 2 2 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 2 1 1 1 2 0 1 1 1 1 2 2 01 1 2 1 2 2 2 10 1 2 1 1 1 2 0 1 1 1 1 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 ...
output:
0 3 1 3 0 1 0 1 2 0 0 2 0 1 2 0 1 3 1 0 1 2 1 0 0 1 3 2 1 0 1 3 3 2 1 0 1 0 0 1 0 1 0 2 2 1 0 1 2 1 1 0 2 0 2 3 1 0 0 1 2 0 0 1 0 1 0 1 1 0 1 2 2 0 0 2 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 2 0 3 0 1 0 0 1 1 0 1 0 1 2 0 2 1 0 0 3 1 2 0 1 3 2 1 0 0 1 2 0 2 0 0 1 0 1 1 0 1 0 1 0 1 0 1 2 1 0 3 1 0 3 0 1 0 1 ...
result:
ok 200000 lines
Test #4:
score: 0
Accepted
time: 33ms
memory: 5792kb
input:
11 20 00010111000 1 6 1 11 5 6 8 11 1 4 3 8 4 11 1 7 5 9 1 4 6 10 5 6 1 7 5 10 1 10 9 11 6 8 1 4 8 11 1 4 10 20 0101000010 3 4 2 2 4 8 4 6 6 7 3 7 3 3 1 5 1 5 6 8 2 2 2 4 2 6 5 7 1 3 2 5 6 8 7 9 5 8 3 10 4 20 1011 2 4 1 4 1 3 2 3 1 1 2 2 1 2 2 4 1 2 3 4 3 4 3 4 1 4 2 2 1 4 1 3 1 1 1 3 1 3 2 2 4 20 1...
output:
16 55 53 25 13 15 43 52 41 33 34 40 43 45 35 28 25 33 45 37 19 20 35 38 36 41 36 29 36 29 22 31 20 23 28 20 21 10 14 30 2 10 5 7 10 9 7 2 0 10 0 10 2 1 9 6 7 4 7 8 4 9 1 6 8 3 5 7 3 7 6 8 6 9 6 7 2 0 5 3 66 105 83 68 92 137 92 76 85 92 127 120 119 104 124 65 70 88 61 53 40 43 25 21 32 59 67 32 29 50...
result:
ok 200000 lines
Test #5:
score: 0
Accepted
time: 51ms
memory: 5864kb
input:
11 200 11100010010 2 3 3 7 1 7 3 10 1 3 7 11 2 8 4 8 9 10 9 11 2 7 1 4 9 11 6 7 4 4 8 10 2 6 2 3 1 2 5 7 2 7 1 3 3 4 2 10 9 10 6 11 3 11 3 9 9 10 2 6 5 10 1 8 4 9 6 7 8 11 3 9 7 10 1 9 4 5 5 8 5 7 2 7 6 8 10 10 5 10 7 11 1 11 6 10 2 11 1 4 4 8 6 11 7 10 8 10 4 5 7 10 7 8 4 4 1 6 7 11 3 5 4 9 3 9 8 1...
output:
27 22 29 25 30 39 34 17 15 12 18 22 33 35 40 45 54 36 34 37 39 52 54 37 39 33 40 51 37 46 52 24 26 24 16 7 35 30 32 40 39 37 28 15 41 28 39 4 26 54 49 31 39 26 28 44 46 41 35 26 17 31 24 28 30 22 38 13 18 60 38 36 49 41 41 43 27 28 54 41 14 16 7 8 20 22 45 26 27 20 21 12 27 31 28 21 39 37 39 30 31 2...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 90ms
memory: 5840kb
input:
228 2000 111000100100000001001101001100110001011110001110001000101110101100010011011111000001011011000110111010111101011000010010000111111111100011111011011100111010011100111001010011110110011000100100110011111000110001111001010011001010 23 112 24 165 103 162 86 203 99 204 114 217 55 132 168 184 110...
output:
13974 13044 13700 13434 14000 13220 13546 13913 13184 13533 13051 13689 13533 14119 14470 13742 13980 13022 13167 13648 13592 13159 13028 13041 12964 12996 12792 12539 12039 11974 12336 12742 12841 12831 12730 12004 12065 12352 13037 11923 12332 14242 13475 13935 13121 12996 12755 13353 13720 13043 ...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 174ms
memory: 12304kb
input:
20000 20000 110010001110111001001001011110011011011011101011010000011100100100110000011111000010010101001001110101010000011010101110001100111010000101000010110100011111001100001110011011001011010000100110010001000101111101001011100110101111110110100001100100110100000100100001011100111011000101111010...
output:
99977542 98746996 98989557 99015753 98938270 98605428 99504163 99699325 101118187 100862580 99993292 99728608 101006398 100940632 100522798 99799311 99585772 100035886 99976445 99131130 99309148 99370536 100535551 99600860 99595679 99735286 99976663 100435885 100334687 100103891 100055339 100160376 ...
result:
ok 200000 lines
Test #8:
score: 0
Accepted
time: 263ms
memory: 25348kb
input:
200000 200000 1101110010111101001110011011011100110000111011010010001110010111010000111100010101100111111010010100111110001001011000010110000100111111011110101101011011011101000010000110010011001011101000000100010110001100001010110010011101010100000011101111001110001110110000101101111011111101000101...
output:
25901941 994525462 2814500 3463763 9230330 28640886 26981481 14997778 13823451 6099927 24702020 21362157 11973234 13511974 21653636 33119640 40350328 46109651 29192352 43766507 30728437 28870157 45189617 4217943 13558652 35410757 20571398 40319106 40216880 18748167 997839045 17848827 33465234 615861...
result:
ok 200000 lines
Test #9:
score: 0
Accepted
time: 260ms
memory: 26116kb
input:
200000 200000 1110111011100101000100110100111011011011111011111100110000001011010001010110001000101110101100100010100001110011111110000000100101100100011011000001110001100100011110000001111011111001101101110001100000101001000001000001101111011001101010100011100100100001000100111010110111101110000100...
output:
2996976 988387591 974626789 985502887 993615462 990275063 19203830 35696796 34289774 7267993 22056809 5091142 997828555 1539157 997787283 4900319 987896873 997340091 993638482 646650 995227298 17206077 22155672 27082357 4722230 24086385 35208979 32166288 35436320 985667659 997480097 988679642 694097...
result:
ok 200000 lines
Test #10:
score: 0
Accepted
time: 209ms
memory: 25136kb
input:
200000 200000 0110001110111111001111110001001110110111001111111100011110111100100110111100010100111010100110000100001110011111011011010111111001101110001011110010011111010000111101010110110111010110100100010011110001101101101101110000000010100010100111110000101111011000110000101000010001010110111111...
output:
988220745 991618043 995353102 43218945 966357434 971782588 948018714 980810727 27797113 53021088 23781501 39601625 967254286 975505074 976134175 73222692 979117703 64837391 50012902 73270693 19854546 7138045 60686015 71233145 20864017 62206852 50231821 50375154 47803471 28033289 29278344 35572675 14...
result:
ok 200000 lines
Test #11:
score: 0
Accepted
time: 241ms
memory: 24564kb
input:
200000 200000 1001110010001000011010101100000101100000111011101001101000000110010101101111110100011111001011011100001101001110100111010000000010001111001011011010000101010111101110111111100011010001110001001110011111011010010101101111100110000110101100100000011110110110011100111011101000010110100010...
output:
15407731 14631678 10186954 10345130 23847449 19860104 10808937 982977033 980356736 962694321 979467129 46038861 44085763 996388027 994522500 992200054 985014110 986398855 18482220 31196285 985715396 982645871 978310933 985212490 989962508 726523 21528316 18120979 25301777 8202316 6324376 995798193 9...
result:
ok 200000 lines
Test #12:
score: 0
Accepted
time: 245ms
memory: 24580kb
input:
200000 200000 0010011111010000110101000011110010101101110011000001000111010010100000100101101000011110010001111010000010101000000010100110011010010110011110110010101111100010001000111000001010010110111000110111000000011101101001011100011111110001100001111100010101001101101000101101101100100110010001...
output:
15506154 19348083 15746021 14628980 32334683 33654933 36224089 50873722 9847255 40651090 42120167 41528380 22636212 13786942 11412334 11873979 18281213 26693110 36507317 24846136 989656082 984635105 9059232 2580548 23212772 22950175 46305459 6758484 6053136 37780773 40099104 55511708 22877321 339317...
result:
ok 200000 lines
Test #13:
score: 0
Accepted
time: 252ms
memory: 24608kb
input:
200000 200000 1011010011001010111111001110110111000000000100100101011011100101000111010100010101000001010011111111111101000000100110110000110011110101011110101111100101000110010000001110000110111110111001000100100000111000000010101111011011111000110111111101011011110010001110110110100100010101011010...
output:
4606987 990360003 992738299 986383034 993014365 987669948 995664674 988276581 988873616 976938498 979101136 985430484 2565996 19548107 13130299 993838803 972233325 995501405 12769099 988692913 14410100 21699482 977804151 983846398 993716775 2571363 16441249 15782766 15593059 23323619 979633325 27776...
result:
ok 200000 lines
Test #14:
score: 0
Accepted
time: 231ms
memory: 25568kb
input:
200000 200000 1100101010110000111100011011010000101100000100011001101101111011100111111110001010101000110101001001100110111011100001100101110111101110010010001110001001011011011011011101101111011101110100110101110111111100101111111100110000011001111110100011110000011111111110100000000000100111101000...
output:
2393949 992730082 972611510 970251279 989437013 985877121 982257978 982959060 987600156 45641948 30059952 979943946 986888253 981389778 978967476 978126848 980481621 17817645 60426483 45758808 16835699 16586467 13373729 6741689 964511911 977717722 991981395 990826974 978075401 19704839 7193456 45368...
result:
ok 200000 lines
Test #15:
score: 0
Accepted
time: 246ms
memory: 25100kb
input:
200000 200000 0101100111101010110100110110100100001101111000110011010011111110101000010100100111110000100101101111001001010101000000110011001110110100000111100010100011101011001111001010101101100001101100110110000011111001000001001111011101000100001011000011111011101101101010110011000010111100111001...
output:
10297534 980029753 30272619 49375218 50632169 69574288 6797467 975065422 62087979 981950427 49855469 57837339 22715009 83393559 78649052 74244695 75889469 62421920 77415773 6572226 40586704 34350302 19139901 19264382 4935761 48990001 32994216 48972163 33566566 8869513 14871104 22941027 28170197 1087...
result:
ok 200000 lines
Test #16:
score: 0
Accepted
time: 249ms
memory: 25220kb
input:
200000 200000 0100011011111000010011111001000011100011101001010111011000101001001001111010111001110001101111111000110111111111101110110101000011010111000111010001101001000110000101001101000001100010101101000000010001001100001100111100111110101100000110001110011001010000001110000101001110001100000010...
output:
47026902 40495162 27149747 33363453 30911117 26108909 30730419 42927718 7603813 6364035 31042501 785203 974526721 974629452 974483169 24562058 31743526 24682968 19166722 11218277 996640683 32644571 28773258 17356726 17787261 18074809 67670633 37296794 26805347 30084028 30261128 31216228 15159508 378...
result:
ok 200000 lines
Test #17:
score: 0
Accepted
time: 262ms
memory: 24604kb
input:
200000 200000 1010010110110010011001001100110110001110001111111111100110111111101100010000000100101100111101011110111010110110111011101111001011001010010011011101000111110011001100111011001000000010100010110001100100001011110010000111100010101111011101011110010010101011111010010011111010101110010001...
output:
64855899 37247247 55246159 17086703 12325666 20301217 976171122 960745510 423388 11055803 30095418 973334427 973479528 975055740 984907581 992422626 20482449 7416938 9353933 17514662 14818478 18430532 19184520 23370654 7214842 991356723 25528201 28366255 41290790 38524173 45023405 36380190 37693504 ...
result:
ok 200000 lines