社区讨论

十七岁青年机房晕倒,原因竟是.....

P4739 [CERC2017] Donut Drone参与者 27已保存回复 30

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
30 条
当前快照
1 份
快照标识符
@mhj1zkzt
此快照首次捕获于
2025/11/03 19:25
4 个月前
此快照最后确认于
2025/11/03 20:36
4 个月前
查看原帖
WA #1 求助
CPP
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T>
inline void read(T&x){
	int w = 0; x = 0;
	char ch = getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') w = 1;
		ch = getchar();
	}
	while(ch>='0' && ch<='9'){
		x = (x<<1)+(x<<3)+(ch^48);
		ch = getchar();
	}
	if(w) x = ~x+1;
}
template <typename T,typename...Args>
inline void read(T&t,Args&...args){
	read(t); read(args...);
}
template <typename T>
inline T Max(T x,T y){ return (x > y ? x : y); }
template <typename T>
inline T Min(T x,T y){ return (x < y ? x : y); }
template <typename T>
inline T Abs(T x){ return (x < 0 ? ~x+1 : x); }
#define int long long
const int N = 2e3+10,LG = 35;
int n,m,q,a[N][N];
char opt[10];
int pos[N][N];
inline pair<int,int> get(int x,int y){
	int ty = (y==m ? 1 : y+1);
	int x1 = x;
	int x2 = (x==n ? 1 : x+1);
	int x3 = (x==1 ? n : x-1);
	int maxn = Max(a[x1][ty],Max(a[x2][ty],a[x3][ty]));
	if(maxn==a[x1][ty]) return {x1,ty};
	if(maxn==a[x2][ty]) return {x2,ty};
	return {x3,ty};
}
inline pair<int,int> get(pair<int,int> x){
	return get(x.first,x.second);
}
int st[LG][N];
struct{
	int val[N];
}tr[N<<2];
inline void push_up(int p){
	for(int i=1;i<=n;++i){
		tr[p].val[i] = tr[p<<1|1].val[tr[p<<1].val[i]];
	}
}
inline void build(int p,int nl,int nr){
	if(nl==nr){
		for(int i=1;i<=n;++i){
			tr[p].val[i] = pos[nl][i];
		}
		return ;
	}
	int mid = (nl+nr) >> 1;
	build(p<<1,nl,mid);
	build(p<<1|1,mid+1,nr);
	push_up(p);
}
inline void update(int p,int nl,int nr,int x){
	if(nl==nr){
		for(int i=1;i<=n;++i){
			tr[p].val[i] = pos[nl][i];
		}
		return ;
	}
	int mid = (nl+nr) >> 1;
	if(x<=mid) update(p<<1,nl,mid,x);
	else update(p<<1|1,mid+1,nr,x);
	push_up(p);
}
inline void change(int x,int y,int k){
	y = (y==1 ? m : y-1);
	for(int i=1;i<=n;++i){
		pos[y][i] = get(i,y).first;
	}
	update(1,1,m,y);
	for(int i=1;i<=n;++i){
		st[0][i] = tr[1].val[i];
	}
	for(int k=1;k<LG;++k){
		for(int i=1;i<=n;++i){
			st[k][i] = st[k-1][st[k-1][i]];
		}
	}
}
int main(){=

	read(n,m);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			read(a[i][j]);
		}
	}	
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			pos[j][i] = get(i,j).first;
		}
	}
	build(1,1,m);
	for(int i=1;i<=n;++i){
		st[0][i] = tr[1].val[i];
	}
	for(int k=1;k<LG;++k){
		for(int i=1;i<=n;++i){
			st[k][i] = st[k-1][st[k-1][i]];
		}
	}
	read(q);
	pair <int,int> now = {1,1};
	for(int i=1,x,y,k;i<=q;++i){
		scanf("%s",opt);
		if(opt[0]=='c'){
			read(x,y,k);
			a[x][y] = k;
			change(x,y,k);	
		}
		else{
			read(k);
			while(k && now.second!=1){
				now = get(now);
				--k;	
			}
			int tmp = k/m;
			for(int j=LG-1;j>=0;--j){
				if(tmp>=(1<<j)){
					tmp -= (1<<j);
					now.first = st[j][now.first];
				}
			}
			k = k%m;
			while(k){
				now = get(now);
				--k;
			}
			printf("%d %d\n",now.first,now.second);
		}
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}

回复

30 条回复,欢迎继续交流。

正在加载回复...