# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100818 | 2019-03-14T16:39:09 Z | MohamedAhmed0 | Topovi (COCI15_topovi) | C++14 | 1827 ms | 40056 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 181 ms | 6264 KB | Output is correct |
7 | Correct | 139 ms | 5660 KB | Output is correct |
8 | Correct | 130 ms | 4600 KB | Output is correct |
9 | Correct | 129 ms | 4800 KB | Output is correct |
10 | Correct | 155 ms | 4956 KB | Output is correct |
11 | Correct | 1771 ms | 39980 KB | Output is correct |
12 | Correct | 1763 ms | 39824 KB | Output is correct |
13 | Correct | 1691 ms | 40056 KB | Output is correct |
14 | Correct | 1757 ms | 39760 KB | Output is correct |
15 | Correct | 1827 ms | 40000 KB | Output is correct |
16 | Correct | 1716 ms | 40052 KB | Output is correct |
17 | Correct | 1650 ms | 39952 KB | Output is correct |
18 | Correct | 1697 ms | 39884 KB | Output is correct |
19 | Correct | 1721 ms | 39840 KB | Output is correct |
20 | Correct | 1757 ms | 40056 KB | Output is correct |