Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. //Adjustment Office - NEERC 2015 - https://codeforces.com/gym/100851
  2. #include <cstdio>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. #define FILENAME "adjustment"
  8.  
  9. int main() {
  10.   freopen(FILENAME ".in", "r", stdin);
  11.   freopen(FILENAME ".out", "w", stdout);
  12.   int n, q;
  13.   scanf("%d %d", &n, &q);
  14.   set <int> r;
  15.   set <int> c;
  16.   long long sr = n * 1LL * (n + 1) / 2;
  17.   long long nr = n;
  18.   long long sc = sr;
  19.   long long nc = n;
  20.   while (q--) {
  21.     char ch = getchar();
  22.     while (ch != 'R' && ch != 'C') {
  23.       ch = getchar();
  24.     }
  25.     int id;
  26.     scanf("%d", &id);
  27.     if (ch == 'R') {
  28.       if (r.find(id) != r.end()) {
  29.         printf("0\n");
  30.       } else {
  31.         r.insert(id);
  32.         printf("%lld\n", sc + id * nc);
  33.         sr -= id;
  34.         nr--;
  35.       }
  36.     } else {
  37.       if (c.find(id) != c.end()) {
  38.         printf("0\n");
  39.       } else {
  40.         c.insert(id);
  41.         printf("%lld\n", sr + id * nr);
  42.         sc -= id;
  43.         nc--;
  44.       }
  45.     }
  46.   }
  47.   return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement