답안 #152179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152179 2019-09-06T17:01:53 Z karma 운세 보기 2 (JOI14_fortune_telling2) C++14
35 / 100
121 ms 27768 KB
#include<bits/stdc++.h>
#define pb      emplace_back

using namespace std;

const int N = int(2e5) + 3;
const int M = int(6e5) + 3;

vector<int> v, c[N];
int n, m, a[N], b[N], t[N], p[N];
int l[M << 2], h[M << 2], st[M << 2];

void Build(int x, int low, int high) {
     l[x] = low, h[x] = high;
     if(l[x] == h[x]) {
        st[x] = p[l[x]];
        return;
     }
     int mid = (low + high) >> 1;
     Build(x << 1, low, mid);
     Build(x << 1 | 1, mid + 1, high);
     st[x] = max(st[x << 1], st[x << 1 | 1]);
}

int Query(int x, int low, int high) {
    if(high < low) return -1;
    if(l[x] > high || h[x] < low) return -1;
    if(l[x] >= low && h[x] <= high) return st[x];
    return max(Query(x << 1, low, high), Query(x << 1 | 1, low, high));
}

int Pos(int x) {return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;}
void Update(int x) {
    for(; x > 0; x -= (x & -x)) ++l[x];
}
int Get(int x) {
    int res = 0;
    for(; x <= int(v.size()); x += (x & -x)) res += l[x];
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        v.pb(a[i]), v.pb(b[i]);
    }
    for(int i = 0; i < m; ++i) cin >> t[i], v.pb(t[i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    memset(&p, -1, sizeof p);
    for(int i = 0; i < m; ++i) p[t[i] = Pos(t[i])] = i;
    Build(1, 1, int(v.size()));
    for(int i = 0; i < n; ++i) {
       a[i] = Pos(a[i]), b[i] = Pos(b[i]);
       c[Query(1, min(a[i], b[i]), max(a[i], b[i]) - 1) + 1].pb(i);
    }
    fill(l, l + int(v.size()) + 1, 0);
    long long res = 0;
    for(int i = m; i >= 0; --i) {
       if(i - m) Update(t[i]);
       for(int id: c[i]) {
           h[id] = Get(max(a[id], b[id]));
           if(i == 0 && a[id] < b[id]) ++h[id];
           if(h[id] & 1) res += v[min(a[id], b[id]) - 1];
           else res += v[max(a[id], b[id]) - 1];
       }
    }
    cout << res;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
2 Correct 7 ms 5880 KB Output is correct
3 Correct 9 ms 6008 KB Output is correct
4 Correct 8 ms 6008 KB Output is correct
5 Correct 8 ms 6008 KB Output is correct
6 Correct 8 ms 6008 KB Output is correct
7 Correct 8 ms 6008 KB Output is correct
8 Correct 8 ms 6008 KB Output is correct
9 Correct 8 ms 6008 KB Output is correct
10 Correct 8 ms 5880 KB Output is correct
11 Correct 8 ms 5900 KB Output is correct
12 Correct 8 ms 6008 KB Output is correct
13 Correct 8 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
2 Correct 7 ms 5880 KB Output is correct
3 Correct 9 ms 6008 KB Output is correct
4 Correct 8 ms 6008 KB Output is correct
5 Correct 8 ms 6008 KB Output is correct
6 Correct 8 ms 6008 KB Output is correct
7 Correct 8 ms 6008 KB Output is correct
8 Correct 8 ms 6008 KB Output is correct
9 Correct 8 ms 6008 KB Output is correct
10 Correct 8 ms 5880 KB Output is correct
11 Correct 8 ms 5900 KB Output is correct
12 Correct 8 ms 6008 KB Output is correct
13 Correct 8 ms 6008 KB Output is correct
14 Correct 23 ms 6976 KB Output is correct
15 Correct 43 ms 8048 KB Output is correct
16 Correct 64 ms 9804 KB Output is correct
17 Correct 84 ms 10108 KB Output is correct
18 Correct 83 ms 10100 KB Output is correct
19 Correct 102 ms 10100 KB Output is correct
20 Correct 83 ms 10100 KB Output is correct
21 Correct 81 ms 10228 KB Output is correct
22 Correct 57 ms 10100 KB Output is correct
23 Correct 54 ms 8692 KB Output is correct
24 Correct 54 ms 8692 KB Output is correct
25 Correct 57 ms 10228 KB Output is correct
26 Correct 60 ms 9972 KB Output is correct
27 Correct 75 ms 10236 KB Output is correct
28 Correct 64 ms 10140 KB Output is correct
29 Correct 77 ms 10184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
2 Correct 7 ms 5880 KB Output is correct
3 Correct 9 ms 6008 KB Output is correct
4 Correct 8 ms 6008 KB Output is correct
5 Correct 8 ms 6008 KB Output is correct
6 Correct 8 ms 6008 KB Output is correct
7 Correct 8 ms 6008 KB Output is correct
8 Correct 8 ms 6008 KB Output is correct
9 Correct 8 ms 6008 KB Output is correct
10 Correct 8 ms 5880 KB Output is correct
11 Correct 8 ms 5900 KB Output is correct
12 Correct 8 ms 6008 KB Output is correct
13 Correct 8 ms 6008 KB Output is correct
14 Correct 23 ms 6976 KB Output is correct
15 Correct 43 ms 8048 KB Output is correct
16 Correct 64 ms 9804 KB Output is correct
17 Correct 84 ms 10108 KB Output is correct
18 Correct 83 ms 10100 KB Output is correct
19 Correct 102 ms 10100 KB Output is correct
20 Correct 83 ms 10100 KB Output is correct
21 Correct 81 ms 10228 KB Output is correct
22 Correct 57 ms 10100 KB Output is correct
23 Correct 54 ms 8692 KB Output is correct
24 Correct 54 ms 8692 KB Output is correct
25 Correct 57 ms 10228 KB Output is correct
26 Correct 60 ms 9972 KB Output is correct
27 Correct 75 ms 10236 KB Output is correct
28 Correct 64 ms 10140 KB Output is correct
29 Correct 77 ms 10184 KB Output is correct
30 Runtime error 121 ms 27768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -