2 solutions
-
2
注意到每个格子只会被最后一次涂色覆盖,倒序处理即可。
set的功能恰好支持查询用插入。map已经输的体无完肤了!#include<bits/stdc++.h> #define int long long #define I using #define love namespace #define copying std; I love copying; int h,w,C,q; struct QUERY{ int t,n,c; }qy[300005]; int ans[300005]; set<int>heng,shu; signed main(){ scanf("%lld%lld%lld%lld",&h,&w,&C,&q); for(int i=1;i<=q;i++)scanf("%lld%lld%lld",&qy[i].t,&qy[i].n,&qy[i].c); for(int i=q;i>=1;i--){ int t=qy[i].t; int n=qy[i].n; int c=qy[i].c; if(t==1){ if(heng.find(n)==heng.end()){ heng.insert(n); ans[c]+=w-shu.size(); } } if(t==2){ if(shu.find(n)==shu.end()){ shu.insert(n); ans[c]+=h-heng.size(); } } } for(int i=1;i<=C;i++)printf("%lld ",ans[i]); } -
1
#include<bits/stdc++.h> using namespace std; #define int long long map<int, int>vish, visl; int tc[300006]; int h, w, c, q; struct no { int cz, hl, col; } n[300005]; signed main() { cin >> h >> w; cin >> c >> q; int tp = q; while (q--) { cin >> n[q + 1].cz >> n[q + 1].hl >> n[q + 1].col; } for (int i = 1; i <= tp; i++) { // cout << n[i].cz << n[i].col << n[i].hl << endl; // cout << vish[n[i].hl] << endl; if (n[i].cz == 1 ) { if (! vish[n[i].hl]) { tc[n[i].col] += w; h--; vish[n[i].hl] = 1; } } else { if (! visl[n[i].hl]) { tc[n[i].col] += h; w--; visl[n[i].hl] = 1; } } } for (int i = 1; i <= c; i++)cout << tc[i] << " "; }
- 1
Information
- ID
- 609
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 33
- Accepted
- 9
- Uploaded By