Submission #100821

#TimeUsernameProblemLanguageResultExecution timeMemory
100821MohamedAhmed0Topovi (COCI15_topovi)C++14
120 / 120
384 ms45380 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; struct chash { int operator()(pair<int , int> x) const { return x.first* 31 + x.second; } }; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; gp_hash_table< pair<int, int> , long long , chash> mp ; gp_hash_table<int , long long , custom_hash>rows , columns ; gp_hash_table<int , long long , custom_hash>rowcnt , columncnt ; long long n , k , p ; long long ans = 0ll ; void update(int r , int c , int x) { ans -= (n - rowcnt[columns[c]]) ; ans -= (n - columncnt[rows[r]]) ; //handle double counting if(rows[r] == columns[c]) ans++ ; rowcnt[rows[r]]-- ; rows[r] ^= x ; rowcnt[rows[r]]++; columncnt[columns[c]]-- ; columns[c] ^= x ; columncnt[columns[c]]++ ; ans += (n - rowcnt[columns[c]]) ; ans += (n - columncnt[rows[r]]) ; //handle double counting if(rows[r] == columns[c]) ans-- ; return ; } int main() { scanf("%lld %lld %lld" , &n , &k , &p) ; rowcnt[0] = columncnt[0] = n ; for(int i = 0 ; i < k ; ++i) { int a , b ; long long c ; scanf("%d %d %lld" , &a , &b , &c) ; mp[{a , b}] = c ; update(a , b , c) ; } while(p--) { int a , b , c , d ; scanf("%d %d %d %d" , &a , &b , &c , &d) ; int x = mp[{a , b}] ; update(a , b , x) ; update(c , d , x) ; mp[{c , d}] = x ; printf("%lld\n" , ans) ; } return 0 ; }

Compilation message (stderr)

topovi.cpp: In function 'int main()':
topovi.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld %lld" , &n , &k , &p) ;
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %lld" , &a , &b , &c) ;
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d" , &a , &b , &c , &d) ;
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...