답안 #258111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258111 2020-08-05T11:27:28 Z fedoseevtimofey 운세 보기 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 4596 KB
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

struct SegmentTree {
  int n;
  vector <int> t;
  SegmentTree(int nn) {
    n = nn;
    t.resize(4 * n, -1);
  }
  void modify(int i, int val, int l, int r, int v) {
    if (l == r) {
      t[v] = max(t[v], val);
    } else {
      int m = (l + r) >> 1;
      if (i <= m) modify(i, val, l, m, 2 * v + 1);
      else modify(i, val, m + 1, r, 2 * v + 2);
      t[v] = max(t[2 * v + 1], t[2 * v + 2]);
    } 
  }
  int get(int ql, int qr, int l, int r, int v) {
    if (qr < l || r < ql) return -1;
    if (ql <= l && r <= qr) return t[v];
    int m = (l + r) >> 1;
    return max(get(ql, qr, l, m, 2 * v + 1), get(ql, qr, m + 1, r, 2 * v + 2));
  }
};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, k;
  cin >> n >> k;
  vector <int> a(n), b(n);
  vector <int> c;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    c.push_back(a[i]);
    c.push_back(b[i]);
  } 
  vector <int> t(k);
  for (int i = 0; i < k; ++i) {
    cin >> t[i];
    c.push_back(t[i]);
  }
  sort(c.begin(), c.end());
  c.resize(unique(c.begin(), c.end()) - c.begin());
  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
    b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
  }
  for (int i = 0; i < k; ++i) {
    t[i] = lower_bound(c.begin(), c.end(), t[i]) - c.begin();
  }
  int m = c.size();
  SegmentTree st(m); 
  for (int i = 0; i < k; ++i) {
    st.modify(t[i], i, 0, m - 1, 0);
  }
  vector <int> when(n, -1);
  for (int i = 0; i < n; ++i) {
    int mn = min(a[i], b[i]);
    int mx = max(a[i], b[i]);
    if (mn < mx) {
      when[i] = st.get(mn, mx - 1, 0, m - 1, 0);
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    int st = 0;
    int go = when[i] + 1;
    if (when[i] != -1 && b[i] > a[i]) {
      st = 1;
    }
    for (int j = go; j < k; ++j) {
      if (a[i] <= t[j] && b[i] <= t[j]) {
        st ^= 1;
      }
    }  
    if (st == 0) ans += c[a[i]];
    else ans += c[b[i]];
  }
  cout << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 18 ms 1408 KB Output is correct
15 Correct 34 ms 2420 KB Output is correct
16 Correct 50 ms 3568 KB Output is correct
17 Correct 71 ms 4468 KB Output is correct
18 Correct 74 ms 4596 KB Output is correct
19 Correct 65 ms 4468 KB Output is correct
20 Correct 77 ms 4596 KB Output is correct
21 Correct 64 ms 4468 KB Output is correct
22 Correct 46 ms 3468 KB Output is correct
23 Correct 55 ms 3060 KB Output is correct
24 Correct 51 ms 2932 KB Output is correct
25 Correct 47 ms 3568 KB Output is correct
26 Correct 2287 ms 3588 KB Output is correct
27 Correct 2866 ms 3828 KB Output is correct
28 Correct 2130 ms 3940 KB Output is correct
29 Execution timed out 3094 ms 4212 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 18 ms 1408 KB Output is correct
15 Correct 34 ms 2420 KB Output is correct
16 Correct 50 ms 3568 KB Output is correct
17 Correct 71 ms 4468 KB Output is correct
18 Correct 74 ms 4596 KB Output is correct
19 Correct 65 ms 4468 KB Output is correct
20 Correct 77 ms 4596 KB Output is correct
21 Correct 64 ms 4468 KB Output is correct
22 Correct 46 ms 3468 KB Output is correct
23 Correct 55 ms 3060 KB Output is correct
24 Correct 51 ms 2932 KB Output is correct
25 Correct 47 ms 3568 KB Output is correct
26 Correct 2287 ms 3588 KB Output is correct
27 Correct 2866 ms 3828 KB Output is correct
28 Correct 2130 ms 3940 KB Output is correct
29 Execution timed out 3094 ms 4212 KB Time limit exceeded