#include <cstdio>
#include <map>
#include <utility>
#include <cassert>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_LIM = lim,REPN = 1;REPN <= REPN_LIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("Line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 1e5 + 100;
std::map<std::pair<int,int>,int> id;
std::map<int,int> val_x,val_y;
std::map<int,int> cnt_x,cnt_y;
ll ans;
void modify(const int x,const int y,const int v){
ans -= 1ll * cnt_x[val_x[x]] * cnt_y[val_x[x]];
cnt_x[val_x[x]]--;
ans += 1ll * cnt_x[val_x[x]] * cnt_y[val_x[x]];
val_x[x] ^= v;
ans -= 1ll * cnt_x[val_x[x]] * cnt_y[val_x[x]];
cnt_x[val_x[x]]++;
ans += 1ll * cnt_x[val_x[x]] * cnt_y[val_x[x]];
ans -= 1ll * cnt_y[val_y[y]] * cnt_x[val_y[y]];
cnt_y[val_y[y]]--;
ans += 1ll * cnt_y[val_y[y]] * cnt_x[val_y[y]];
val_y[y] ^= v;
ans -= 1ll * cnt_y[val_y[y]] * cnt_x[val_y[y]];
cnt_y[val_y[y]]++;
ans += 1ll * cnt_y[val_y[y]] * cnt_x[val_y[y]];
}
int n,k,q,w[maxn];
int main(){
// std::freopen("topovi.in","r",stdin);
// std::freopen("topovi.out","w",stdout);
std::scanf("%d %d %d",&n,&k,&q);
cnt_x[0] = cnt_y[0] = n;
ans = 1ll * n * n;
rep(i,1,k){
int x,y; std::scanf("%d %d %d",&x,&y,w + i);
modify(x,y,w[i]);
id[std::make_pair(x,y)] = i;
}
repn(q){
int fx,fy,tx,ty; std::scanf("%d %d %d %d",&fx,&fy,&tx,&ty);
let it = id.find(std::make_pair(fx,fy));
let t = it->second,v = w[t];
id.erase(it);
id[std::make_pair(tx,ty)] = t;
modify(fx,fy,v);
modify(tx,ty,v);
std::printf("%lld\n",1ll * n * n - ans);
}
std::fclose(stdin);
std::fclose(stdout);
return 0;
}
Compilation message
topovi.cpp: In function 'int main()':
topovi.cpp:43:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | std::scanf("%d %d %d",&n,&k,&q);
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
topovi.cpp:47:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | int x,y; std::scanf("%d %d %d",&x,&y,w + i);
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:53:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | int fx,fy,tx,ty; std::scanf("%d %d %d %d",&fx,&fy,&tx,&ty);
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
284 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
170 ms |
4776 KB |
Output is correct |
7 |
Correct |
138 ms |
4552 KB |
Output is correct |
8 |
Correct |
104 ms |
3748 KB |
Output is correct |
9 |
Correct |
107 ms |
3876 KB |
Output is correct |
10 |
Correct |
127 ms |
3888 KB |
Output is correct |
11 |
Correct |
1417 ms |
33472 KB |
Output is correct |
12 |
Correct |
1545 ms |
33492 KB |
Output is correct |
13 |
Correct |
1378 ms |
33432 KB |
Output is correct |
14 |
Correct |
1376 ms |
33404 KB |
Output is correct |
15 |
Correct |
1404 ms |
33624 KB |
Output is correct |
16 |
Correct |
1427 ms |
33416 KB |
Output is correct |
17 |
Correct |
1409 ms |
33624 KB |
Output is correct |
18 |
Correct |
1394 ms |
33412 KB |
Output is correct |
19 |
Correct |
1412 ms |
33548 KB |
Output is correct |
20 |
Correct |
1378 ms |
33496 KB |
Output is correct |