답안 #946327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946327 2024-03-14T13:51:44 Z jay_jayjay 커다란 상품 (IOI17_prize) C++14
99.75 / 100
31 ms 3264 KB
// {{{1
extern "C" int __lsan_is_turned_off() { return 1; };
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>

#ifdef DEBUG
#define dprintf(args...) fprintf(stderr,args)
#endif
#ifndef DEBUG
#define dprintf(args...) 42
#endif
#define ll long long
#define all(x) (x).begin(),(x).end()

#define mod int(1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f

void sleep(int x) { this_thread::sleep_for(chrono::seconds(x)); }
struct { template<typename T> operator T() { T x; cin>>x; return x; } } in;

struct __rng {
        mt19937_64 _rng;
        __rng() {
                ll ctime = chrono::high_resolution_clock::now().time_since_epoch().count();
                _rng = mt19937_64(ctime);
        }
        
        ll randint(ll l, ll h) {
                return uniform_int_distribution<int>(l,h)(_rng);
        }
} rng;
// 1}}}
#define rank rank2
// #define DBG

#define N 200000

vector<int> ask(int i);

#ifdef DBG
int n; vector<int> arr;
int q=0;
vector<int> ask(int i) {
        q++;
        int l=0,r=0;
        for(int j=0;j<i;j++)if(arr[j]<arr[i]) l++;
        for(int j=i+1;j<n;j++)if(arr[j]<arr[i])r++;
        return vector<int>{l,r};
}
#endif
int ans[N][2];
int best=-1;


void ask2(int i) {
        if(best == i) return;
        
        if(ans[i][0]+ans[i][1] == 0) {
                auto x = ask(i);
                ans[i][0] = x[0];
                ans[i][1] = x[1];
                if(ans[i][0]+ans[i][1] == 0) assert(best==-1), best &= i;
        }
}

int rank(int i) {
        ask2(i);
        return ans[i][0]+ans[i][1];
}

int right(int i) {
        ask2(i);
        return ans[i][1];
}



// lower rank is more rare
void solve(int l, int r) {
        if(right(l) == right(r)) return;
        if(r<l) return;
        if(l==r) return void(rank(l));
        while(rank(l) != rank(r)) {
                while(rank(l) < rank(r)) l++;
                while(rank(l) > rank(r)) r--;
        }
        
        int m=(l+r)/2;
        solve(l,m);
        solve(m,r);
}

int find_best(int n) {
        solve(0, n-1);
        assert(best >= 0);
        return best;
}

#ifdef DBG
int main() {
        n=in;arr.resize(n);for(auto&x:arr)x=in;
        
        int ans = find_best(n);
        printf("%d\n",ans);
        printf("q=%d\n",q);
        return arr[ans]!=1;
}
#endif

Compilation message

prize.cpp:22:73: warning: 'in' defined but not used [-Wunused-variable]
   22 | struct { template<typename T> operator T() { T x; cin>>x; return x; } } in;
      |                                                                         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 0 ms 448 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 448 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 440 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 0 ms 448 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 0 ms 444 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 1 ms 444 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 1032 KB Output is correct
12 Correct 2 ms 1284 KB Output is correct
13 Correct 2 ms 1032 KB Output is correct
14 Correct 4 ms 960 KB Output is correct
15 Correct 20 ms 2780 KB Output is correct
16 Correct 22 ms 2864 KB Output is correct
17 Correct 31 ms 2604 KB Output is correct
18 Correct 25 ms 2332 KB Output is correct
19 Correct 23 ms 2472 KB Output is correct
20 Correct 21 ms 1288 KB Output is correct
21 Correct 25 ms 2484 KB Output is correct
22 Correct 19 ms 2580 KB Output is correct
23 Correct 1 ms 500 KB Output is correct
24 Correct 2 ms 1228 KB Output is correct
25 Correct 20 ms 2128 KB Output is correct
26 Correct 19 ms 2424 KB Output is correct
27 Correct 1 ms 496 KB Output is correct
28 Correct 19 ms 2304 KB Output is correct
29 Correct 23 ms 1948 KB Output is correct
30 Correct 29 ms 1980 KB Output is correct
31 Correct 23 ms 2360 KB Output is correct
32 Correct 2 ms 1024 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 28 ms 2360 KB Output is correct
35 Correct 1 ms 500 KB Output is correct
36 Correct 28 ms 2156 KB Output is correct
37 Correct 3 ms 1020 KB Output is correct
38 Correct 1 ms 500 KB Output is correct
39 Correct 20 ms 2452 KB Output is correct
40 Correct 22 ms 2756 KB Output is correct
41 Correct 24 ms 2740 KB Output is correct
42 Correct 25 ms 2492 KB Output is correct
43 Correct 30 ms 2348 KB Output is correct
44 Correct 24 ms 3200 KB Output is correct
45 Correct 22 ms 2064 KB Output is correct
46 Correct 22 ms 2236 KB Output is correct
47 Correct 25 ms 2136 KB Output is correct
48 Correct 29 ms 2080 KB Output is correct
49 Correct 18 ms 2580 KB Output is correct
50 Correct 19 ms 2772 KB Output is correct
51 Correct 24 ms 3020 KB Output is correct
52 Correct 25 ms 2156 KB Output is correct
53 Correct 1 ms 500 KB Output is correct
54 Correct 28 ms 2152 KB Output is correct
55 Correct 20 ms 3264 KB Output is correct
56 Correct 23 ms 2452 KB Output is correct
57 Correct 24 ms 1964 KB Output is correct
58 Correct 19 ms 2540 KB Output is correct
59 Correct 24 ms 1932 KB Output is correct
60 Correct 20 ms 3048 KB Output is correct
61 Correct 1 ms 504 KB Output is correct
62 Correct 1 ms 504 KB Output is correct
63 Correct 1 ms 708 KB Output is correct
64 Correct 1 ms 500 KB Output is correct
65 Correct 1 ms 448 KB Output is correct
66 Correct 2 ms 448 KB Output is correct
67 Correct 2 ms 448 KB Output is correct
68 Correct 2 ms 448 KB Output is correct
69 Correct 3 ms 448 KB Output is correct
70 Correct 2 ms 452 KB Output is correct
71 Correct 21 ms 2048 KB Output is correct
72 Correct 2 ms 1092 KB Output is correct
73 Correct 19 ms 2784 KB Output is correct
74 Correct 24 ms 2180 KB Output is correct
75 Correct 1 ms 456 KB Output is correct
76 Correct 17 ms 2292 KB Output is correct
77 Partially correct 22 ms 2808 KB Partially correct - number of queries: 5025
78 Correct 3 ms 1216 KB Output is correct
79 Correct 11 ms 2756 KB Output is correct
80 Correct 24 ms 2312 KB Output is correct
81 Correct 25 ms 2640 KB Output is correct
82 Correct 20 ms 2432 KB Output is correct
83 Correct 1 ms 452 KB Output is correct
84 Correct 18 ms 2072 KB Output is correct
85 Correct 22 ms 2840 KB Output is correct
86 Correct 2 ms 960 KB Output is correct
87 Correct 1 ms 900 KB Output is correct
88 Correct 2 ms 704 KB Output is correct
89 Correct 2 ms 704 KB Output is correct
90 Correct 0 ms 448 KB Output is correct
91 Correct 1 ms 700 KB Output is correct
92 Correct 1 ms 448 KB Output is correct
93 Correct 2 ms 700 KB Output is correct
94 Correct 2 ms 1260 KB Output is correct
95 Correct 2 ms 1168 KB Output is correct
96 Correct 2 ms 1268 KB Output is correct
97 Correct 1 ms 476 KB Output is correct