# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91302 | 2018-12-27T04:28:41 Z | Retro3014 | Fortune Telling 2 (JOI14_fortune_telling2) | C++17 | 359 ms | 122400 KB |
#include <iostream> #include <algorithm> #include <vector> #include <deque> using namespace std; #define MAX_N 200000 #define INF 1000000000 struct S{ int x, y; bool b=false; bool operator <(const S &a)const{ return x<a.x; } }; int N, K; S arr[MAX_N+1]; int Q[MAX_N+1]; int two=1; int seg[MAX_N*4+1], seg2[MAX_N*4+1]; void update(int x, int y){ x+=two; seg[x]=y; x/=2; while(x){ seg[x]=min(seg[x*2], seg[x*2+1]); x/=2; } return; } void update2(int x){ x+=two; while(x){ seg2[x]++; x/=2; } return; } int sum(int x, int y){ int ret=0; x+=two; y+=two; while(x<=y){ if(x==y){ return ret+seg2[x]; } if(x%2==1){ ret+=seg2[x++]; } if(y%2==0){ ret+=seg2[y--]; } x/=2; y/=2; } return ret; } struct S2{ int x, y; bool operator <(const S2 &a)const{ return x<a.x; } }; int calc(int x, int y){ x+=two; y+=two; int ret=INF; while(x<=y){ if(x==y){ return min(ret, seg[x]); } if(x%2==1){ ret=min(ret, seg[x]); x++; } if(y%2==0){ ret=min(ret, seg[y]); y--; } x/=2; y/=2; } return ret; } deque<S2> dq; long long ans=0; int main(){ scanf("%d%d", &N, &K); while(two<=K) two*=2; for(int i=1; i<two*2; i++){ seg[i]=INF; } for(int i=0; i<N; i++){ scanf("%d%d", &arr[i].x, &arr[i].y); if(arr[i].x>arr[i].y){ arr[i].b=true; int tmp=arr[i].x; arr[i].x=arr[i].y; arr[i].y=tmp; } } sort(arr, arr+N); for(int i=0; i<K; i++){ scanf("%d", &Q[i]); update(i, Q[i]); dq.push_back((S2){Q[i], i}); } sort(dq.begin(), dq.end()); for(int i=0; i<N; i++){ S now = arr[i]; while(!dq.empty() && (dq.front().x < now.x)){ update(dq.front().y, INF); update2(dq.front().y); dq.pop_front(); } if(calc(0, K-1) < now.y){ now.b = true; } int s=0, e=K, mid; while(s<e){ mid=(s+e)/2; if(calc(mid, K-1)<now.y){ s=mid+1; }else{ e=mid; } } mid=K-s-sum(s, K-1); now.b=((int)now.b+mid)%2; if(now.b){ ans+=(long long)now.y; }else{ ans+=(long long)now.x; } } printf("%lld", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2832 KB | Output is correct |
3 | Correct | 4 ms | 2868 KB | Output is correct |
4 | Correct | 4 ms | 2868 KB | Output is correct |
5 | Correct | 4 ms | 3004 KB | Output is correct |
6 | Correct | 5 ms | 3072 KB | Output is correct |
7 | Correct | 5 ms | 3072 KB | Output is correct |
8 | Correct | 4 ms | 3168 KB | Output is correct |
9 | Correct | 4 ms | 3168 KB | Output is correct |
10 | Correct | 4 ms | 3192 KB | Output is correct |
11 | Correct | 5 ms | 3300 KB | Output is correct |
12 | Correct | 4 ms | 3300 KB | Output is correct |
13 | Correct | 4 ms | 3384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2832 KB | Output is correct |
3 | Correct | 4 ms | 2868 KB | Output is correct |
4 | Correct | 4 ms | 2868 KB | Output is correct |
5 | Correct | 4 ms | 3004 KB | Output is correct |
6 | Correct | 5 ms | 3072 KB | Output is correct |
7 | Correct | 5 ms | 3072 KB | Output is correct |
8 | Correct | 4 ms | 3168 KB | Output is correct |
9 | Correct | 4 ms | 3168 KB | Output is correct |
10 | Correct | 4 ms | 3192 KB | Output is correct |
11 | Correct | 5 ms | 3300 KB | Output is correct |
12 | Correct | 4 ms | 3300 KB | Output is correct |
13 | Correct | 4 ms | 3384 KB | Output is correct |
14 | Correct | 13 ms | 4008 KB | Output is correct |
15 | Correct | 23 ms | 4940 KB | Output is correct |
16 | Correct | 34 ms | 6036 KB | Output is correct |
17 | Correct | 46 ms | 7732 KB | Output is correct |
18 | Correct | 48 ms | 8792 KB | Output is correct |
19 | Correct | 45 ms | 10056 KB | Output is correct |
20 | Correct | 50 ms | 11236 KB | Output is correct |
21 | Correct | 47 ms | 12272 KB | Output is correct |
22 | Correct | 41 ms | 13028 KB | Output is correct |
23 | Correct | 37 ms | 13712 KB | Output is correct |
24 | Correct | 38 ms | 14400 KB | Output is correct |
25 | Correct | 38 ms | 15036 KB | Output is correct |
26 | Correct | 51 ms | 16308 KB | Output is correct |
27 | Correct | 59 ms | 17352 KB | Output is correct |
28 | Correct | 55 ms | 18444 KB | Output is correct |
29 | Correct | 72 ms | 19688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2832 KB | Output is correct |
3 | Correct | 4 ms | 2868 KB | Output is correct |
4 | Correct | 4 ms | 2868 KB | Output is correct |
5 | Correct | 4 ms | 3004 KB | Output is correct |
6 | Correct | 5 ms | 3072 KB | Output is correct |
7 | Correct | 5 ms | 3072 KB | Output is correct |
8 | Correct | 4 ms | 3168 KB | Output is correct |
9 | Correct | 4 ms | 3168 KB | Output is correct |
10 | Correct | 4 ms | 3192 KB | Output is correct |
11 | Correct | 5 ms | 3300 KB | Output is correct |
12 | Correct | 4 ms | 3300 KB | Output is correct |
13 | Correct | 4 ms | 3384 KB | Output is correct |
14 | Correct | 13 ms | 4008 KB | Output is correct |
15 | Correct | 23 ms | 4940 KB | Output is correct |
16 | Correct | 34 ms | 6036 KB | Output is correct |
17 | Correct | 46 ms | 7732 KB | Output is correct |
18 | Correct | 48 ms | 8792 KB | Output is correct |
19 | Correct | 45 ms | 10056 KB | Output is correct |
20 | Correct | 50 ms | 11236 KB | Output is correct |
21 | Correct | 47 ms | 12272 KB | Output is correct |
22 | Correct | 41 ms | 13028 KB | Output is correct |
23 | Correct | 37 ms | 13712 KB | Output is correct |
24 | Correct | 38 ms | 14400 KB | Output is correct |
25 | Correct | 38 ms | 15036 KB | Output is correct |
26 | Correct | 51 ms | 16308 KB | Output is correct |
27 | Correct | 59 ms | 17352 KB | Output is correct |
28 | Correct | 55 ms | 18444 KB | Output is correct |
29 | Correct | 72 ms | 19688 KB | Output is correct |
30 | Correct | 102 ms | 26608 KB | Output is correct |
31 | Correct | 139 ms | 29536 KB | Output is correct |
32 | Correct | 194 ms | 33392 KB | Output is correct |
33 | Correct | 281 ms | 39200 KB | Output is correct |
34 | Correct | 68 ms | 41196 KB | Output is correct |
35 | Correct | 288 ms | 46960 KB | Output is correct |
36 | Correct | 297 ms | 52796 KB | Output is correct |
37 | Correct | 287 ms | 58556 KB | Output is correct |
38 | Correct | 285 ms | 64436 KB | Output is correct |
39 | Correct | 287 ms | 70156 KB | Output is correct |
40 | Correct | 240 ms | 75808 KB | Output is correct |
41 | Correct | 280 ms | 81652 KB | Output is correct |
42 | Correct | 286 ms | 87484 KB | Output is correct |
43 | Correct | 192 ms | 91768 KB | Output is correct |
44 | Correct | 196 ms | 97128 KB | Output is correct |
45 | Correct | 200 ms | 102576 KB | Output is correct |
46 | Correct | 221 ms | 106756 KB | Output is correct |
47 | Correct | 294 ms | 110552 KB | Output is correct |
48 | Correct | 359 ms | 116424 KB | Output is correct |
49 | Correct | 301 ms | 122400 KB | Output is correct |