#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second
long long n,m,nn=0,wg[50069],aa[50069],dsu[50069],a[50069],pst[50069],sbt[50069],pr[50069][16],bl[50069],ls[50069],vy[4]={-1,0,1,0},vx[4]={0,1,0,-1};
pair<long long,long long> as[50069];
bitset<50069> vtd;
vector<long long> al[50069];
long long fd(long long x)
{
if(dsu[x]!=x)
{
dsu[x]=fd(dsu[x]);
}
return dsu[x];
}
void dfs(long long x)
{
long long i,j,sz=al[x].size(),l;
nn++;
a[nn]=aa[x];
pst[x]=nn;
sbt[x]=1;
for(i=0;i<sz;i++)
{
l=al[x][i];
pr[l][0]=x;
for(j=1;j-1<bl[pr[l][j-1]];j++)
{
pr[l][j]=pr[pr[l][j-1]][j-1];
}
bl[l]=j;
dfs(l);
sbt[x]+=sbt[l];
}
}
int main()
{
long long t,rr,i,j,im,ky,p,y,x,w,yy,xx,pp,z;
scanf("%lld%lld%lld",&n,&m,&t);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
p=i*m+j;
scanf("%lld",wg+p);
as[p]={wg[p],p};
}
}
sort(as,as+n*m);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
p=i*m+j;
scanf("%lld",aa+p);
}
}
for(i=0;i<n*m;i++)
{
p=as[i].sc;
y=p/m;
x=p%m;
vtd[p]=1;
dsu[p]=p;
for(im=0;im<4;im++)
{
yy=y+vy[im];
xx=x+vx[im];
pp=yy*m+xx;
if(yy>=0&&xx>=0&&yy<n&&xx<m&&vtd[pp]&&fd(pp)!=p)
{
al[p].push_back(fd(pp));
dsu[fd(pp)]=p;
}
}
}
dfs(p);
for(rr=1;rr<=t;rr++)
{
scanf("%lld%lld%lld%lld",&ky,&x,&y,&w);
y--;
x--;
p=y*m+x;
if(ky==1)
{
a[pst[p]]=w;
}
else if(wg[p]>w)
{
printf("0\n");
}
else
{
for(i=15;i+1;i--)
{
if(i<bl[p]&&wg[pr[p][i]]<=w)
{
p=pr[p][i];
}
}
z=0;
for(i=pst[p];i<=pst[p]+sbt[p]-1;i++)
{
z+=ls[a[i]]<rr;
ls[a[i]]=rr;
}
printf("%lld\n",z);
}
}
}
Compilation message
pokemonmaster.cpp: In function 'int main()':
pokemonmaster.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf("%lld%lld%lld",&n,&m,&t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
pokemonmaster.cpp:55:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
55 | scanf("%lld",wg+p);
| ~~~~~^~~~~~~~~~~~~
pokemonmaster.cpp:65:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
65 | scanf("%lld",aa+p);
| ~~~~~^~~~~~~~~~~~~
pokemonmaster.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
90 | scanf("%lld%lld%lld%lld",&ky,&x,&y,&w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pokemonmaster.cpp:87:5: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
87 | dfs(p);
| ~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
15544 KB |
Output is correct |
2 |
Correct |
78 ms |
15744 KB |
Output is correct |
3 |
Correct |
50 ms |
15868 KB |
Output is correct |
4 |
Correct |
43 ms |
15480 KB |
Output is correct |
5 |
Correct |
79 ms |
15832 KB |
Output is correct |
6 |
Correct |
159 ms |
15864 KB |
Output is correct |
7 |
Correct |
80 ms |
15480 KB |
Output is correct |
8 |
Correct |
74 ms |
15608 KB |
Output is correct |
9 |
Correct |
76 ms |
15528 KB |
Output is correct |
10 |
Correct |
83 ms |
15864 KB |
Output is correct |
11 |
Correct |
76 ms |
15872 KB |
Output is correct |
12 |
Correct |
86 ms |
15864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
14712 KB |
Output is correct |
2 |
Correct |
34 ms |
15096 KB |
Output is correct |
3 |
Correct |
34 ms |
15096 KB |
Output is correct |
4 |
Correct |
38 ms |
14968 KB |
Output is correct |
5 |
Correct |
40 ms |
15360 KB |
Output is correct |
6 |
Correct |
41 ms |
15096 KB |
Output is correct |
7 |
Correct |
51 ms |
13688 KB |
Output is correct |
8 |
Correct |
52 ms |
14072 KB |
Output is correct |
9 |
Correct |
52 ms |
13816 KB |
Output is correct |
10 |
Correct |
51 ms |
14072 KB |
Output is correct |
11 |
Correct |
51 ms |
14072 KB |
Output is correct |
12 |
Correct |
50 ms |
14072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5070 ms |
15172 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
15544 KB |
Output is correct |
2 |
Correct |
78 ms |
15744 KB |
Output is correct |
3 |
Correct |
50 ms |
15868 KB |
Output is correct |
4 |
Correct |
43 ms |
15480 KB |
Output is correct |
5 |
Correct |
79 ms |
15832 KB |
Output is correct |
6 |
Correct |
159 ms |
15864 KB |
Output is correct |
7 |
Correct |
80 ms |
15480 KB |
Output is correct |
8 |
Correct |
74 ms |
15608 KB |
Output is correct |
9 |
Correct |
76 ms |
15528 KB |
Output is correct |
10 |
Correct |
83 ms |
15864 KB |
Output is correct |
11 |
Correct |
76 ms |
15872 KB |
Output is correct |
12 |
Correct |
86 ms |
15864 KB |
Output is correct |
13 |
Execution timed out |
5068 ms |
15868 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
15544 KB |
Output is correct |
2 |
Correct |
78 ms |
15744 KB |
Output is correct |
3 |
Correct |
50 ms |
15868 KB |
Output is correct |
4 |
Correct |
43 ms |
15480 KB |
Output is correct |
5 |
Correct |
79 ms |
15832 KB |
Output is correct |
6 |
Correct |
159 ms |
15864 KB |
Output is correct |
7 |
Correct |
80 ms |
15480 KB |
Output is correct |
8 |
Correct |
74 ms |
15608 KB |
Output is correct |
9 |
Correct |
76 ms |
15528 KB |
Output is correct |
10 |
Correct |
83 ms |
15864 KB |
Output is correct |
11 |
Correct |
76 ms |
15872 KB |
Output is correct |
12 |
Correct |
86 ms |
15864 KB |
Output is correct |
13 |
Correct |
38 ms |
14712 KB |
Output is correct |
14 |
Correct |
34 ms |
15096 KB |
Output is correct |
15 |
Correct |
34 ms |
15096 KB |
Output is correct |
16 |
Correct |
38 ms |
14968 KB |
Output is correct |
17 |
Correct |
40 ms |
15360 KB |
Output is correct |
18 |
Correct |
41 ms |
15096 KB |
Output is correct |
19 |
Correct |
51 ms |
13688 KB |
Output is correct |
20 |
Correct |
52 ms |
14072 KB |
Output is correct |
21 |
Correct |
52 ms |
13816 KB |
Output is correct |
22 |
Correct |
51 ms |
14072 KB |
Output is correct |
23 |
Correct |
51 ms |
14072 KB |
Output is correct |
24 |
Correct |
50 ms |
14072 KB |
Output is correct |
25 |
Execution timed out |
5070 ms |
15172 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |