QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#268957#5109. Spider WalkjuampiWA 332ms8696kbC++171.8kb2023-11-29 04:22:262023-11-29 04:22:27

Judging History

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

  • [2023-11-29 04:22:27]
  • 评测
  • 测评结果:WA
  • 用时:332ms
  • 内存:8696kb
  • [2023-11-29 04:22:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mk make_pair
#define lowbit(x) (x&(-x))
#define pb emplace_back
#define pr pair<int,int>
#define let const auto
const int N=2e5+5,M=5e5+5;
int read(){
	int x=0,f=1; char c=getchar();
	while(('0'>c||c>'9')&&c!='-') c=getchar();
	if(c=='-') f=0,c=getchar();
	while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f?x:-x;
}
int n,m,a[N],s;

int nxt(int x,int c){return (x+c)%n;}
int pre(int x,int c){return (x-c+n)%n;}
vector <pr> lines;

ll c[N];
void add(int x,const int y){x++;while(x<=n) c[x]+=y,x+=lowbit(x);}
int query(int x){ll res=0;x++; while(x) res+=c[x],x-=lowbit(x); return res;}
void padd(int l,int r,int x){add(l,x),add(r+1,-x);}
void work(int l,int r){
	if(l<=r) padd(l,r,-1);
	else padd(l,n-1,-1),padd(0,r,-1);
}

int main(){
	n=read(),m=read(),s=read()-1;
	for(int i=1; i<=m; i++){
		int d=read(),t=read()-1;
		lines.pb(d,t);
	}
	for(int i=0; i<n; i++) padd(i,i,min(abs(s-i),n-abs(s-i)));
	sort(lines.begin(),lines.end(),greater <pr>{});
	for(auto &[d,t]:lines){
		int nx=nxt(t,1);
		cout<<d<<" "<<t<<endl;
		int v1=query(t),v2=query(nx);
		
		assert(abs(v1-v2)<=1);
		if(v1==v2) continue;
		if(v1>v2){
			padd(t,t,-1);
			int cur=0;
			for(int i=18; ~i; i--) if(cur+(1<<i)<=n-2&&query(pre(t,cur+(1<<i)))==v1+cur+(1<<i))
				cur+=1<<i;
			if(cur) work(pre(t,cur),pre(t,1));
			if(query(nxt(nx,1))!=v2-1) padd(nx,nx,1);
		}
		else{
			padd(nx,nx,-1);
			int cur=0;
			for(int i=18; ~i; i--) if(cur+(1<<i)<=n-2&&query(nxt(nx,cur+(1<<i)))==v2+cur+(1<<i))
				cur+=1<<i;
			if(cur) work(nxt(nx,1),nxt(nx,cur));
			if(query(pre(t,1))!=v1-1) padd(t,t,1);
		}
	}
	for(int i=0; i<n; i++) printf("%d\n",query(i));
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 332ms
memory: 8696kb

input:

200000 500000 116205
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

500000 100000
499999 99999
499998 99998
499997 99997
499996 99996
499995 99995
499994 99994
499993 99993
499992 99992
499991 99991
499990 99990
499989 99989
499988 99988
499987 99987
499986 99986
499985 99985
499984 99984
499983 99983
499982 99982
499981 99981
499980 99980
499979 99979
499978 99978
...

result:

wrong answer 1st lines differ - expected: '2', found: '500000 100000'