# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
959264 | nihon | Topovi (COCI15_topovi) | C++14 | 670 ms | 32556 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
int n,k,p,i,j,x,y,x2,y2,a,o;
ll t;
unordered_map<int,int> r,c,f,g;
map<pair<int,int> ,int> m;
int main()
{
cin>>n>>k>>p;
f[0]=g[0]=n;
for(i=1;i<=k;++i)
{
cin>>x>>y>>a;
m[{x,y}]=a;
r[x]^=a;
c[y]^=a;
}
for(auto e:r)
{
if(!e.second) continue;
f[e.second]++;
o++;
f[0]--;
}
for(auto e:c)
{
if(!e.second) continue;
g[e.second]++;
g[0]--;
}
for(auto e:r)
{
if(!a) continue;
a=e.second;
t+=(n-g[a]);
t-=(n-g[a]-g[0]);
}
for(auto e:c)
{
if(!a) continue;
a=e.second;
t+=(n-f[a]);
}
while(p--)
{
cin>>x>>y>>x2>>y2;
if(x==x2 && y==y2) continue;
t-=n-f[c[y]];
t-=n-g[r[x]];
t-=n-f[c[y2]];
t-=n-g[r[x2]];
if(r[x]!=c[y]) t++;
if(r[x2]!=c[y2]) t++;
if(y==y2) t+=n-f[c[y]];
if(x==x2) t+=n-g[r[x]];
if(x!=x2 && y!=y2)
{
if(r[x2]!=c[y]) t++;
if(r[x]!=c[y2]) t++;
}
if(x!=x2)
{
f[r[x]]--;
r[x]^=m[{x,y}];
f[r[x]]++;
f[r[x2]]--;
r[x2]^=m[{x,y}];
f[r[x2]]++;
}
if(y!=y2)
{
g[c[y]]--;
c[y]^=m[{x,y}];
g[c[y]]++;
g[c[y2]]--;
c[y2]^=m[{x,y}];
g[c[y2]]++;
}
m[{x2,y2}]=m[{x,y}];
m.erase({x,y});
t+=n-f[c[y]];
t+=n-g[r[x]];
t+=n-f[c[y2]];
t+=n-g[r[x2]];
if(r[x]!=c[y]) t--;
if(r[x2]!=c[y2]) t--;
if(y==y2) t-=n-f[c[y]];
if(x==x2) t-=n-g[r[x]];
if(x!=x2 && y!=y2)
{
if(r[x2]!=c[y]) t--;
if(r[x]!=c[y2]) t--;
}
cout<<t<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |