QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663229#9409. SensorsTheShuMoAC ✓2755ms495484kbC++143.2kb2024-10-21 14:15:322024-10-21 14:15:33

Judging History

This is the latest submission verdict.

  • [2024-10-21 14:15:33]
  • Judged
  • Verdict: AC
  • Time: 2755ms
  • Memory: 495484kb
  • [2024-10-21 14:15:32]
  • Submitted

answer

#include<bits/stdc++.h>
#define fo(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define rep(i,l,r) for(ll i(l),i##end(r);i<=i##end;++i)
#define per(i,r,l) for(ll i(r),i##end(l);i>=i##end;--i)
#define dbg(x) cerr<<#x<<" "<<x<<'\n';
#define ll long long
#define gc getchar
#define pc putchar
using namespace std;
namespace WrongIO
{
	#define Ts template<typename Ty,typename... Ar>
	#define Tp template<typename Ty>
	Tp Ty wmax(Ty a,Ty b){return a>=b? a:b;}
	Tp Ty wmin(Ty a,Ty b){return a<=b? a:b;}
	Tp void read(Ty &x){x=0;Ty opt=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();if(c=='-')opt=-1,c=gc();while(isdigit(c))x=(x<<3)+(x<<1),x+=c-'0',c=gc();x*=opt;return;}
	Tp void write(Ty x){short OI_USE[150],OI_top=0;if(x<=0) if(x==0)pc('0');else pc('-'),x*=-1;while(x)OI_USE[++OI_top]=x%10,x/=10;while(OI_top--)pc(OI_USE[OI_top+1]+'0');return;}
    void writec(char c[]){int len=strlen(c);for(int i=0;i<len;i++)pc(c[i]);}
    void writes(string s){int len=s.length();for(int i=0;i<len;i++)pc(s[i]);}
    void readc(char &c,int l,int r){c=gc(); while(c!=EOF&&(c<l||c>r)) c=gc();}
    void readc(char &c,char val){c=gc();while(c!=EOF&&c!=val) c=gc();}
    void readc(char val){char c;c=gc();while(c!=EOF&&c!=val) c=gc();}
    void readls(string &s){char c=gc();while(c!='\n') s.push_back(c),c=gc();}
    Ts void read(Ty &x,Ar &...y) {read(x),read(y...);}
    Tp void writeln(Ty x) {write(x),pc('\n');}
    Tp void writesp(Ty x) {write(x),pc(' ');} 
    #undef Ts
	#undef Tp
} using namespace WrongIO;
const ll N=5e5+50;
ll n,m;
vector<ll> vt[N*4],qs[N];
ll st[N*4],vis[N],vks[N*4],wz[N];
void update(ll pos)
{
	st[pos]=0;
	if(pos*2<=4*n) st[pos]+=st[pos<<1];
	if(pos*2+1<=4*n) st[pos]+=st[pos<<1|1];
}
void cle(ll L,ll R,ll pos)
{
	vt[pos].clear();
	if(L==R) return vks[pos]=1,wz[L]=pos,st[pos]=1,void();
	ll mid=(L+R)/2;
	cle(L,mid,pos<<1);
	cle(mid+1,R,pos<<1|1);
	update(pos); vks[pos]=(st[pos]==1? 1:2);
}
void dt(ll L,ll R,ll EL,ll ER,ll vlx,ll pos)
{
	if(L>ER||R<EL) return;
	if(EL<=L&&R<=ER) return qs[vlx].push_back(pos),vt[pos].push_back(vlx),void();
	ll mid=(L+R)/2;
	dt(L,mid,EL,ER,vlx,pos<<1);
	dt(mid+1,R,EL,ER,vlx,pos<<1|1);
}
ll la;
void solve()
{
	read(n,m); la=0;
	rep(i,0,max(n,m)) qs[i].clear(),vis[i]=0,wz[i]=0;
	rep(i,0,4*n) st[i]=0,vks[i]=0;
	cle(1,n,1);
	rep(i,1,m)
	{
		ll u,v; read(u,v); u++; v++;
		if(u-v==0) la+=i*i,vis[i]=1; 
		dt(1,n,u,v,i,1);
	}
	writesp(la);
	rep(i,1,n)
	{
		ll pa; read(pa);
		pa=(pa+la)%n; pa++;
		ll pos=wz[pa]; st[pos]=0;
		while(pos)
		{
			if(pos!=wz[pa]) update(pos);
			if(vks[pos]==2&&st[pos]==1)
			{
				vks[pos]=1;
				for(ll id:vt[pos])
				{
					if(vis[id]==1) continue;
					ll ok=0; 
					for(ll ck:qs[id])
					ok+=st[ck];
					if(ok==1) vis[id]=1,la+=id*id;
				}
				
			}
			if(vks[pos]==1&&st[pos]==0)
			{
				vks[pos]=0;
				for(ll id:vt[pos])
				{
					
					ll ok=0; 
					for(ll ck:qs[id]) ok+=st[ck];
					if(ok==1&&vis[id]==0) vis[id]=1,la+=id*id;
					if(ok==0&&vis[id]==1) vis[id]=0,la-=id*id;
				}
			}
			pos/=2;
		}
		writesp(la);
	}
	pc('\n');
}
ll T;
int main()
{
	//freopen("a.out","w",stdout);
	//fo("t3");
	read(T);
	while(T--) solve();
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 70400kb

input:

3
5 4
2 4
2 3
3 3
0 2
3 2 4 2 0
2 1
1 1
1 0
2 1
0 1
0 0

output:

9 13 29 17 16 0 
1 1 0 
0 1 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 573ms
memory: 116920kb

input:

2227
2 9
0 1
1 1
0 1
0 0
0 1
0 1
0 0
1 1
0 1
1 1
3 1
0 2
1 2 2
8 2
0 2
3 5
7 4 0 3 2 6 4 1
6 2
1 3
0 1
0 0 5 1 4 2
1 6
0 0
0 0
0 0
0 0
0 0
0 0
0
5 1
1 4
0 1 2 3 3
5 3
0 3
4 4
2 2
0 4 0 0 0
5 10
0 2
3 3
1 3
1 4
1 3
0 4
2 4
0 0
0 1
4 4
3 1 3 4 1
8 4
0 5
0 1
6 7
3 4
1 3 3 5 2 3 5 3
2 7
1 1
0 0
0 0
1 1
...

output:

133 220 0 
0 0 1 0 
0 0 0 0 4 4 5 4 0 
0 4 4 4 4 5 0 
91 0 
0 0 0 0 1 0 
13 13 4 0 1 0 
168 249 105 135 136 0 
0 4 13 9 0 0 16 17 0 
79 127 0 
1 54 0 
0 0 25 25 25 61 40 57 21 14 0 
385 0 
0 0 9 71 9 53 69 0 
0 0 9 9 9 46 0 
35 39 203 0 
1 10 9 9 9 54 0 
5 5 5 0 0 
5 13 13 4 16 16 16 0 
4 4 5 5 5 4 ...

result:

ok 2227 lines

Test #3:

score: 0
Accepted
time: 2755ms
memory: 300624kb

input:

1
500000 500000
369902 382967
262235 295509
296241 456925
21398 104992
37225 97384
380549 388723
338331 494405
150247 262207
70049 286642
214690 432702
268101 392964
99683 217894
89569 351594
126467 380939
152103 169827
171887 422097
166531 416410
44667 160325
210347 371355
47557 119914
74437 200422...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...9642788310 20801182804434259 0 '

Test #4:

score: 0
Accepted
time: 136ms
memory: 120284kb

input:

1
500000 500000
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499999
0 499...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 41666791666750000 0 '

Test #5:

score: 0
Accepted
time: 2060ms
memory: 495484kb

input:

1
500000 500000
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499998
1 499...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 41666791666750000 0 '

Test #6:

score: 0
Accepted
time: 778ms
memory: 209100kb

input:

1
500000 250000
0 250000
1 250001
2 250002
3 250003
4 250004
5 250005
6 250006
7 250007
8 250008
9 250009
10 250010
11 250011
12 250012
13 250013
14 250014
15 250015
16 250016
17 250017
18 250018
19 250019
20 250020
21 250021
22 250022
23 250023
24 250024
25 250025
26 250026
27 250027
28 250028
29 2...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...18019441588 4838325779633316 0 '

Extra Test:

score: 0
Extra Test Passed