# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100817 | MohamedAhmed0 | Topovi (COCI15_topovi) | C++14 | 1918 ms | 40460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
map< pair<int , int> , long long> mp ;
map<int , long long>rows , columns ;
map<int , long long>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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |