답안 #100817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100817 2019-03-14T16:35:09 Z MohamedAhmed0 Topovi (COCI15_topovi) C++14
120 / 120
1918 ms 40460 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

topovi.cpp: In function 'int main()':
topovi.cpp:36: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:42: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:49: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) ;
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 177 ms 6680 KB Output is correct
7 Correct 157 ms 6060 KB Output is correct
8 Correct 155 ms 5192 KB Output is correct
9 Correct 146 ms 5240 KB Output is correct
10 Correct 126 ms 5368 KB Output is correct
11 Correct 1700 ms 40352 KB Output is correct
12 Correct 1769 ms 40352 KB Output is correct
13 Correct 1804 ms 40456 KB Output is correct
14 Correct 1724 ms 40312 KB Output is correct
15 Correct 1730 ms 40356 KB Output is correct
16 Correct 1918 ms 40312 KB Output is correct
17 Correct 1816 ms 40460 KB Output is correct
18 Correct 1718 ms 40444 KB Output is correct
19 Correct 1667 ms 40256 KB Output is correct
20 Correct 1782 ms 40364 KB Output is correct