Submission #119431

# Submission time Handle Problem Language Result Execution time Memory
119431 2019-06-21T08:47:44 Z IOrtroiii Fortune Telling 2 (JOI14_fortune_telling2) C++14
100 / 100
293 ms 32080 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 200200;

int n, q;
int x[N], y[N], z[N];
bool sw[N];
bool ft[N];
vector<pair<int, int>> vals;
int rmq[18][N];
vector<pair<int, int>> qs[N];

void mdf(int v) {
   for (; v > 0; v -= v & -v) {
      ft[v] ^= true;
   }
}

bool get(int v) {
   bool ans = false;
   for (; v <= q; v += v & -v) {
      ans ^= ft[v];
   }
   return ans;
}

int get(int l, int r) {
   int LG = __lg(r - l + 1);
   return max(rmq[LG][l], rmq[LG][r - (1 << LG) + 1]);
}

int main() {
   scanf("%d %d", &n, &q);
   for (int i = 1; i <= n; ++i) {
      scanf("%d %d", x + i, y + i);
   }
   for (int i = 1; i <= q; ++i) {
      scanf("%d", z + i);
      vals.emplace_back(z[i], i);
   }
   sort(vals.begin(), vals.end());
   for (int i = 0; i < q; ++i) {
      rmq[0][i + 1] = vals[i].second;
   }
   for (int i = 1; i < 18; ++i) {
      for (int j = 1; j + (1 << i) - 1 <= q; ++j) {
         rmq[i][j] = max(rmq[i - 1][j], rmq[i - 1][j + (1 << i - 1)]);
      }
   }
   for (int i = 1; i <= n; ++i) {
      int l = min(x[i], y[i]), r = max(x[i], y[i]);
      l = lower_bound(vals.begin(), vals.end(), make_pair(l, 0)) - vals.begin() + 1;
      r = lower_bound(vals.begin(), vals.end(), make_pair(r, 0)) - vals.begin();
      int last = 0;
      if (l <= r) {
         last = get(l, r);
         if (x[i] < y[i]) {
            swap(x[i], y[i]);
         }
      }
      qs[r].emplace_back(i, last + 1);
   }
   for (int i = q - 1; i >= 0; --i) {
      mdf(vals[i].second);
      for (auto v : qs[i]) {
         sw[v.first] = get(v.second);
      }
   }
   long long ans = 0;
   for (int i = 1; i <= n; ++i) {
      if (sw[i]) {
         ans += y[i];
      } else {
         ans += x[i];
      }
   }
   printf("%lld\n", ans);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:49:64: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
          rmq[i][j] = max(rmq[i - 1][j], rmq[i - 1][j + (1 << i - 1)]);
                                                              ~~^~~
fortune_telling2.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &n, &q);
    ~~~~~^~~~~~~~~~~~~~~~~
fortune_telling2.cpp:37:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", x + i, y + i);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:40:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", z + i);
       ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 14 ms 6016 KB Output is correct
15 Correct 24 ms 6900 KB Output is correct
16 Correct 40 ms 7924 KB Output is correct
17 Correct 46 ms 9024 KB Output is correct
18 Correct 44 ms 8944 KB Output is correct
19 Correct 44 ms 8944 KB Output is correct
20 Correct 47 ms 9068 KB Output is correct
21 Correct 40 ms 8812 KB Output is correct
22 Correct 30 ms 8936 KB Output is correct
23 Correct 30 ms 9072 KB Output is correct
24 Correct 31 ms 9072 KB Output is correct
25 Correct 31 ms 8816 KB Output is correct
26 Correct 37 ms 8816 KB Output is correct
27 Correct 43 ms 8944 KB Output is correct
28 Correct 41 ms 8944 KB Output is correct
29 Correct 44 ms 8960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 14 ms 6016 KB Output is correct
15 Correct 24 ms 6900 KB Output is correct
16 Correct 40 ms 7924 KB Output is correct
17 Correct 46 ms 9024 KB Output is correct
18 Correct 44 ms 8944 KB Output is correct
19 Correct 44 ms 8944 KB Output is correct
20 Correct 47 ms 9068 KB Output is correct
21 Correct 40 ms 8812 KB Output is correct
22 Correct 30 ms 8936 KB Output is correct
23 Correct 30 ms 9072 KB Output is correct
24 Correct 31 ms 9072 KB Output is correct
25 Correct 31 ms 8816 KB Output is correct
26 Correct 37 ms 8816 KB Output is correct
27 Correct 43 ms 8944 KB Output is correct
28 Correct 41 ms 8944 KB Output is correct
29 Correct 44 ms 8960 KB Output is correct
30 Correct 84 ms 21092 KB Output is correct
31 Correct 125 ms 25312 KB Output is correct
32 Correct 189 ms 27624 KB Output is correct
33 Correct 273 ms 31888 KB Output is correct
34 Correct 82 ms 22756 KB Output is correct
35 Correct 280 ms 31848 KB Output is correct
36 Correct 282 ms 31844 KB Output is correct
37 Correct 275 ms 31844 KB Output is correct
38 Correct 262 ms 31600 KB Output is correct
39 Correct 283 ms 32080 KB Output is correct
40 Correct 204 ms 30564 KB Output is correct
41 Correct 277 ms 32048 KB Output is correct
42 Correct 293 ms 31972 KB Output is correct
43 Correct 130 ms 29668 KB Output is correct
44 Correct 126 ms 29668 KB Output is correct
45 Correct 128 ms 29660 KB Output is correct
46 Correct 164 ms 30068 KB Output is correct
47 Correct 145 ms 30528 KB Output is correct
48 Correct 213 ms 31492 KB Output is correct
49 Correct 239 ms 31460 KB Output is correct