QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335196#3061. Donut DronezxcenWA 19ms3772kbC++142.6kb2024-02-22 21:33:462024-02-22 21:33:46

Judging History

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

  • [2024-02-22 21:33:46]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:3772kb
  • [2024-02-22 21:33:46]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>

using namespace std;
const int N=2e3;
int n,m;
int a[N+10][N+10];
int to[N+10];
int q;
int ax,ay;
int vis[N+10];
inline pii move(int x,int y){
	y=(y+1)%m;
	int rx=x;
	if(a[(x+n-1)%n][y]>a[rx][y]){
		rx=(x+n-1)%n;
	}
	if(a[(x+1)%n][y]>a[rx][y]){
		rx=(x+1)%n;
	}
	return {rx,y};
}
inline pii solve(int x,int y){
	while(y){
		pii res=move(x,y);
		x=res.first;
		y=res.second;
	}
	return {x,y};
}
inline pii from(int x,int y){
	int ls=x,rs=x,len=1;
	while(y){
		y=(y+m-1)%m;
		if(move((ls%n+n-1)%n,y).first==ls){
			ls=(ls%n+n-1)%n;
			++len;
		}
		else if(move((ls%n+n)%n,y).first==(ls%n+n-1)%n){
			ls=(ls+1)%n;
			--len;
		}
		if(move((rs%n+n+1)%n,y).first==rs){
			rs=(rs+1)%n;
			++len;
		}
		else if(move((rs%n+n)%n,y).first==(rs%n+n+1)%n){
			rs=(rs%n+n-1)%n;
			--len;
		}
		if(len<0){
			return {-1,-1};
		}
		if(rs-ls+1>=n){
			return {1,0};
		}
	}
	return {ls,rs};
}
inline void work(int x,int y){
	pii res=from(x,y),tmp=move(x,y),res1=solve(tmp.first,tmp.second);
	if(~res.first){
		if(res.first<=res.second){
			for(int i=res.first;i<=res.second;++i){
				to[i]=res1.first;
			}
		}
		else{
			for(int i=res.first;i<n;++i){
				to[i]=res1.first;
			}
			for(int i=0;i<=res.second;++i){
				to[i]=res1.first;
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;++i){
		to[i]=solve(move(i,0).first,1).first;
	}
	ax=0;
	ay=0;
	cin>>q;
	while(q--){
		char op[10];
		cin>>op;
		if(op[0]=='m'){
			int x;
			cin>>x;
//			for(int i=0;i<n;++i){
//				cout<<to[i]+1<<' ';
//			}
//			cout<<endl;
			while(ay&&x){
				pii res=move(ax,ay);
				ax=res.first;
				ay=res.second;
				--x;
			}
			if(!x){
				cout<<ax+1<<' '<<ay+1<<'\n';
			}
			else{
				for(int i=0;i<n;++i){
					vis[i]=0;
				}
				int sum=0;
				while(!vis[ax]&&x>=m){
					vis[ax]=++sum;
					ax=to[ax];
					x-=m;
				}
				if(x<m){
					while(x--){
						pii res=move(ax,ay);
						ax=res.first;
						ay=res.second;
					}
					cout<<ax+1<<' '<<ay+1<<'\n';
				}
				else{
					x=x%((sum-vis[ax]+1)*m);
					while(x>=m){
						ax=to[ax];
						x-=m;
					}
					while(x--){
						pii res=move(ax,ay);
						ax=res.first;
						ay=res.second;
					}
					cout<<ax+1<<' '<<ay+1<<'\n';
				}
			}
		}
		else{
			int x,y,z;
			cin>>x>>y>>z;
			--x;
			--y;
			a[x][y]=z;
			work((x+n-1)%n,(y+m-1)%m);
			work(x,(y+m-1)%m);
			work((x+1)%n,(y+m-1)%m);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

4 4
1 2 9 3
3 5 4 8
4 3 2 7
5 8 1 6
4
move 1
move 1
change 1 4 100
move 1

output:

4 2
1 3
1 4

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

3 4
10 20 30 40
50 60 70 80
90 93 95 99
3
move 4
change 2 1 100
move 4

output:

3 1
2 1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 5ms
memory: 3732kb

input:

20 30
8 1 7 4 3 1 2 1 5 5 2 7 6 4 7 1 2 9 1 9 9 9 9 6 4 9 1 6 3 10
7 3 5 6 5 3 5 3 1 9 8 8 7 7 6 7 5 10 9 6 5 3 8 2 7 10 6 8 4 3
6 4 3 1 7 7 6 7 2 7 3 6 8 6 3 2 7 8 10 8 6 5 6 10 2 6 5 10 10 9
2 5 10 9 4 9 3 6 10 8 1 7 3 3 7 3 3 6 7 5 1 1 10 6 8 5 4 2 1 8
5 1 2 8 3 4 2 4 4 9 6 3 1 5 9 1 9 3 8 3 7 10...

output:

19 10
18 19
3 24
3 30
3 2
4 3
3 8
7 14
3 21
2 27
3 7
3 8
6 16
5 17
3 24
2 27
3 29
3 8
7 12
6 16
3 22
3 2
7 12
3 19
1 22
4 25
4 3
3 5
7 12
3 20
1 22
2 24
3 2
6 11
3 20
2 24
4 4
3 5
5 10
6 11
4 18
2 21
3 29
3 2
3 5
4 9
6 16
2 25
1 26
2 1
4 6
7 15
2 24
3 2
7 12
3 19
3 28
5 4
9 11
9 12
11 17
10 19
12 21...

result:

ok 1945 lines

Test #4:

score: -100
Wrong Answer
time: 19ms
memory: 3772kb

input:

50 50
126812431 909179109 607682292 96000160 425314080 189788877 721251789 103560861 114082307 888028612 277663589 257100764 842807257 327052508 652365304 770138116 384723035 680037089 675501229 509497026 174936063 991259231 761329528 658883078 806406343 741076652 973854314 192609094 398064987 65322...

output:

26 21
21 21
23 49
33 20
46 37
20 42
45 35
23 50
13 17
1 43
23 38
2 47
27 50
23 38
50 50
33 26
34 17
24 34
32 21
34 9
22 6
35 2
1 30
31 40
32 21
31 35
23 17
33 31
26 32
4 9
2 42
33 12
32 8
33 31
35 3
11 15
28 48
17 20
32 30
34 17
23 49
22 14
23 4
1 30
12 29
14 40
48 24
49 27
1 36
37 27
49 47
30 6
38 ...

result:

wrong answer 1st lines differ - expected: '46 21', found: '26 21'