Submission #489750

# Submission time Handle Problem Language Result Execution time Memory
489750 2021-11-24T08:14:01 Z cpp219 Topovi (COCI15_topovi) C++14
30 / 120
610 ms 38204 KB
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e6 + 9;
const ll inf = 1e9 + 7;

map<LL,ll> power;
unordered_map<ll,ll> cntA,cntB,r,c;
ll n,k,Q,ans;

void update(ll x,ll y,ll val){
    ll nwB = r[x] ^ val,nwA = c[y] ^ val;
    ans += cntA[r[x]] - cntA[nwB];
    cntB[r[x]]--; cntB[nwB]++; r[x] = nwB;
    ans += cntB[c[y]] - cntB[nwA];
    cntA[c[y]]--; cntA[nwA]++; c[y] = nwA;
}

ll x,y,w;

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>k>>Q; cntA[0] = cntB[0] = n;
    while(k--){
        cin>>x>>y>>w; update(x,y,w);
        power[{x,y}] = w;
    }
    //debug(ans);
    while(Q--){
        ll x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        update(x1,y1,power[{x1,y1}]); update(x2,y2,power[{x1,y1}]);
        swap(power[{x2,y2}],power[{x1,y1}]);
        cout<<ans<<"\n";
    }
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

topovi.cpp: In function 'int main()':
topovi.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Incorrect 48 ms 5688 KB Output isn't correct
7 Incorrect 34 ms 5140 KB Output isn't correct
8 Incorrect 27 ms 4364 KB Output isn't correct
9 Incorrect 31 ms 4484 KB Output isn't correct
10 Incorrect 33 ms 4552 KB Output isn't correct
11 Incorrect 610 ms 38080 KB Output isn't correct
12 Incorrect 577 ms 38144 KB Output isn't correct
13 Incorrect 568 ms 38048 KB Output isn't correct
14 Incorrect 557 ms 38120 KB Output isn't correct
15 Incorrect 577 ms 38204 KB Output isn't correct
16 Incorrect 573 ms 38032 KB Output isn't correct
17 Incorrect 579 ms 38108 KB Output isn't correct
18 Incorrect 584 ms 38192 KB Output isn't correct
19 Incorrect 576 ms 38032 KB Output isn't correct
20 Incorrect 550 ms 38132 KB Output isn't correct