QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339711 | #3061. Donut Drone | mayunfei | RE | 7ms | 4628kb | C++14 | 2.4kb | 2024-02-27 20:25:46 | 2024-02-27 20:25:47 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define lll __int128
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll rint(ll l,ll r){return uniform_int_distribution<ll>(l,r)(rnd);}
const int maxn=2010;
int n,m,Q,a[maxn][maxn],g[maxn][maxn],nx,ny,f[maxn];
char opt[10];
struct node
{
int u[maxn];
}t[maxn<<2];
node operator + (node X,node Y)
{
for(int i=0;i<n;i++) X.u[i]=Y.u[X.u[i]];
return X;
}
void build(int l,int r,int id)
{
if(l==r)
{
for(int i=0;i<n;i++) t[id].u[i]=g[i][l];
return;
}
int mid=(l+r)>>1;
build(l,mid,id<<1),build(mid+1,r,(id<<1)|1);
t[id]=t[id<<1]+t[(id<<1)|1];
}
void modify(int l,int r,int id,int loc)
{
if(l==r)
{
for(int i=0;i<n;i++) t[id].u[i]=g[i][l];
return;
}
int mid=(l+r)>>1;
if(loc<=mid) modify(l,mid,id<<1,loc);
else modify(mid+1,r,(id<<1)|1,loc);
t[id]=t[id<<1]+t[(id<<1)|1];
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
g[i][j]=i;
if(a[(i-1+n)%n][(j+1)%m]>a[g[i][j]][(j+1)%m]) g[i][j]=(i-1+n)%n;
if(a[(i+1+n)%n][(j+1)%m]>a[g[i][j]][(j+1)%m]) g[i][j]=(i+1+n)%n;
}
}
build(0,m-1,1);
scanf("%d",&Q);
while(Q--)
{
scanf("%s",opt);
if(opt[0]=='m')
{
int len;
scanf("%d",&len);
while(ny!=0&&len) len--,nx=g[nx][ny],ny=(ny+1)%m;
if(!len)
{
printf("%d %d\n",nx+1,ny+1);
continue;
}
memset(f,0,sizeof(f));
int cnt=1;
f[nx]=1;
while(len>=m)
{
nx=t[1].u[nx];
if(f[nx])
{
cnt-=f[nx];
break;
}
f[nx]=++cnt;
len-=m;
}
if(len<m)
{
while(len) len--,nx=g[nx][ny],ny=(ny+1)%m;
printf("%d %d\n",nx+1,ny+1);
continue;
}
len%=(cnt*m);
while(len>=m) nx=t[1].u[nx],len-=m;
while(len) len--,nx=g[nx][ny],ny=(ny+1)%m;
printf("%d %d\n",nx+1,ny+1);
}
else
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
x--,y--;
a[x][y]=z;
y=(y-1+m)%m;
for(int i=0;i<n;i++)
{
if(a[(i-1+n)%n][(y+1)%m]>a[g[i][y]][(y+1)%m]) g[i][y]=(i-1+n)%n;
if(a[i][(y+1)%m]>a[g[i][y]][(y+1)%m]) g[i][y]=i;
if(a[(i+1+n)%n][(y+1)%m]>a[g[i][y]][(y+1)%m]) g[i][y]=(i+1+n)%n;
}
modify(0,m-1,1,y);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3948kb
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: 1ms
memory: 4036kb
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: 7ms
memory: 4628kb
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
Runtime Error
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...