답안 #119430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119430 2019-06-21T08:47:07 Z IOrtroiii 운세 보기 2 (JOI14_fortune_telling2) C++14
35 / 100
92 ms 22940 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 < 17; ++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);
       ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 12 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 6 ms 5220 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 12 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 6 ms 5220 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 15 ms 6272 KB Output is correct
15 Correct 27 ms 7548 KB Output is correct
16 Correct 52 ms 8820 KB Output is correct
17 Correct 47 ms 10096 KB Output is correct
18 Correct 49 ms 10096 KB Output is correct
19 Correct 46 ms 10096 KB Output is correct
20 Correct 46 ms 10096 KB Output is correct
21 Correct 40 ms 9964 KB Output is correct
22 Correct 31 ms 9584 KB Output is correct
23 Correct 30 ms 9712 KB Output is correct
24 Correct 31 ms 9712 KB Output is correct
25 Correct 30 ms 9584 KB Output is correct
26 Correct 35 ms 9712 KB Output is correct
27 Correct 42 ms 10068 KB Output is correct
28 Correct 42 ms 10072 KB Output is correct
29 Correct 44 ms 10096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 12 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 6 ms 5220 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 15 ms 6272 KB Output is correct
15 Correct 27 ms 7548 KB Output is correct
16 Correct 52 ms 8820 KB Output is correct
17 Correct 47 ms 10096 KB Output is correct
18 Correct 49 ms 10096 KB Output is correct
19 Correct 46 ms 10096 KB Output is correct
20 Correct 46 ms 10096 KB Output is correct
21 Correct 40 ms 9964 KB Output is correct
22 Correct 31 ms 9584 KB Output is correct
23 Correct 30 ms 9712 KB Output is correct
24 Correct 31 ms 9712 KB Output is correct
25 Correct 30 ms 9584 KB Output is correct
26 Correct 35 ms 9712 KB Output is correct
27 Correct 42 ms 10068 KB Output is correct
28 Correct 42 ms 10072 KB Output is correct
29 Correct 44 ms 10096 KB Output is correct
30 Incorrect 92 ms 22940 KB Output isn't correct
31 Halted 0 ms 0 KB -