답안 #423305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423305 2021-06-10T23:21:37 Z MDario 커다란 상품 (IOI17_prize) C++11
99.7 / 100
72 ms 6016 KB
    #include "prize.h"
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define F first
    #define S second
    int maxn, abi[200001];
    vector<int> v[200001];
    void update_abi(int xf, int yf){
        while(xf<=maxn){
            abi[xf]+=yf;
            xf+=xf&(-xf);
        }
        return;
    }
    int query_abi1(int xf){
        int cr=0;
        while(xf>0){
            cr+=abi[xf];
            xf-=xf&(-xf);
        }
        return cr;
    }
    int query_abi2(int xf){
        int cr=0, cf=0;
        for(int i=18; i>=0; i--){
            if(cr+(1<<i)<=maxn){
                if(cf+(1<<i)-abi[cr+(1<<i)]<xf){
                    cf+=(1<<i)-abi[cr+(1<<i)];
                    cr+=(1<<i);
                }
            }
        }
        return cr;
    }
    int find_best(int n) {
        if(n<=5000){
            for(int i = 0; i < n; i++) {
                vector<int> res = ask(i);
                if(res[0] + res[1] == 0)
                    return i;
            }
        }
        else{
            maxn=n;
            for(int i = 0; i < 475; i++) {
                v[i]=ask(i);
                if(v[i][0]+v[i][1]==0)return i;
            }
            int x=0, y=0;
            for(int i = 0; i < 475; i++){
                x=max(x, v[i][0]+v[i][1]);
            }
            y=x;
            for(int i = 0; i < 475; i++){
                if(v[i][0]+v[i][1]!=x){
                    y--;
                    update_abi(i+1, 1);
                }
            }
            int l, r, z, c[20];
            for(int i=0; r!=n-1; i++){
                l=475+i*256;
                r=min(l+256-1, n-1);
                z=l-query_abi1(l+1)+1;
                while(l<=r){
                    v[r]=ask(r);
                    if(v[r][0]+v[r][1]!=x){
                        update_abi(r+1, 1);
                        if(v[r][0]+v[r][1]==0)return r;
                        r--;
                        y--;
                    }
                    else break;
                }
                if(l>r||v[r][0]==query_abi1(r+1))continue;
                c[0]=v[r][0]-query_abi1(r);
                for(int t=0; t<c[0]; t++){
                    r--;
                    c[1]=l;
                    c[3]=r;
                    while(c[1]<=c[3]){
                        c[2]=(c[1]+c[3])/2;
                        c[4]=query_abi2(c[2]-l+z);
                        if(v[c[4]].empty())v[c[4]]=ask(c[4]);
                        if(v[c[4]][0]+v[c[4]][1]!=x){
                            y--;
                            update_abi(c[4]+1, 1);
                            if(v[c[4]][0]+v[c[4]][1]==0)return c[4];
                            break;
                        }
                        if(v[c[4]][0]==query_abi1(c[4]+1))c[1]=c[2]+1;
                        else c[3]=c[2]-1;
                    }
                }
            }
        }
    	return 0;
    }

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:62:27: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |             for(int i=0; r!=n-1; i++){
      |                          ~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5000 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 8 ms 5008 KB Output is correct
4 Correct 15 ms 4984 KB Output is correct
5 Correct 15 ms 5012 KB Output is correct
6 Correct 4 ms 5064 KB Output is correct
7 Correct 12 ms 4936 KB Output is correct
8 Correct 15 ms 4936 KB Output is correct
9 Correct 12 ms 4976 KB Output is correct
10 Correct 18 ms 4996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4984 KB Output is correct
2 Correct 9 ms 5000 KB Output is correct
3 Correct 14 ms 5008 KB Output is correct
4 Correct 19 ms 4936 KB Output is correct
5 Correct 11 ms 5004 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 12 ms 4936 KB Output is correct
8 Correct 8 ms 4996 KB Output is correct
9 Correct 8 ms 5000 KB Output is correct
10 Correct 19 ms 4936 KB Output is correct
11 Correct 16 ms 5116 KB Output is correct
12 Correct 9 ms 5000 KB Output is correct
13 Correct 20 ms 5324 KB Output is correct
14 Correct 7 ms 5036 KB Output is correct
15 Correct 16 ms 5096 KB Output is correct
16 Correct 42 ms 5720 KB Output is correct
17 Correct 8 ms 4988 KB Output is correct
18 Correct 42 ms 5952 KB Output is correct
19 Correct 8 ms 4972 KB Output is correct
20 Correct 25 ms 5104 KB Output is correct
21 Correct 24 ms 5316 KB Output is correct
22 Correct 15 ms 4984 KB Output is correct
23 Correct 11 ms 4988 KB Output is correct
24 Correct 9 ms 4996 KB Output is correct
25 Correct 16 ms 5564 KB Output is correct
26 Correct 17 ms 5464 KB Output is correct
27 Correct 8 ms 4988 KB Output is correct
28 Correct 50 ms 5748 KB Output is correct
29 Correct 25 ms 5692 KB Output is correct
30 Correct 50 ms 5852 KB Output is correct
31 Correct 9 ms 4936 KB Output is correct
32 Correct 16 ms 5240 KB Output is correct
33 Correct 3 ms 4936 KB Output is correct
34 Correct 12 ms 5304 KB Output is correct
35 Correct 9 ms 5188 KB Output is correct
36 Correct 12 ms 5268 KB Output is correct
37 Correct 11 ms 4984 KB Output is correct
38 Correct 10 ms 4980 KB Output is correct
39 Correct 34 ms 5312 KB Output is correct
40 Correct 43 ms 5824 KB Output is correct
41 Correct 37 ms 5492 KB Output is correct
42 Correct 39 ms 5516 KB Output is correct
43 Correct 33 ms 5440 KB Output is correct
44 Correct 23 ms 5248 KB Output is correct
45 Correct 11 ms 5272 KB Output is correct
46 Correct 11 ms 4972 KB Output is correct
47 Correct 18 ms 5352 KB Output is correct
48 Correct 30 ms 5564 KB Output is correct
49 Correct 13 ms 4976 KB Output is correct
50 Correct 59 ms 5808 KB Output is correct
51 Correct 28 ms 5496 KB Output is correct
52 Correct 8 ms 4980 KB Output is correct
53 Correct 17 ms 5108 KB Output is correct
54 Correct 13 ms 5364 KB Output is correct
55 Correct 5 ms 5000 KB Output is correct
56 Correct 72 ms 5880 KB Output is correct
57 Correct 42 ms 5568 KB Output is correct
58 Correct 44 ms 5568 KB Output is correct
59 Correct 27 ms 5512 KB Output is correct
60 Correct 35 ms 5516 KB Output is correct
61 Correct 18 ms 5120 KB Output is correct
62 Correct 10 ms 4936 KB Output is correct
63 Correct 22 ms 5108 KB Output is correct
64 Correct 11 ms 4976 KB Output is correct
65 Correct 18 ms 4980 KB Output is correct
66 Correct 11 ms 5108 KB Output is correct
67 Correct 17 ms 4936 KB Output is correct
68 Correct 9 ms 4936 KB Output is correct
69 Correct 22 ms 5008 KB Output is correct
70 Correct 10 ms 5080 KB Output is correct
71 Partially correct 41 ms 5864 KB Partially correct - number of queries: 5030
72 Correct 20 ms 5004 KB Output is correct
73 Correct 51 ms 5888 KB Output is correct
74 Correct 48 ms 5804 KB Output is correct
75 Correct 16 ms 4936 KB Output is correct
76 Correct 55 ms 5852 KB Output is correct
77 Correct 54 ms 5928 KB Output is correct
78 Correct 23 ms 4988 KB Output is correct
79 Correct 32 ms 5444 KB Output is correct
80 Correct 39 ms 5888 KB Output is correct
81 Correct 63 ms 5864 KB Output is correct
82 Correct 52 ms 5800 KB Output is correct
83 Correct 18 ms 5020 KB Output is correct
84 Correct 39 ms 6016 KB Output is correct
85 Correct 25 ms 5888 KB Output is correct
86 Correct 16 ms 5040 KB Output is correct
87 Correct 13 ms 4936 KB Output is correct
88 Correct 20 ms 5052 KB Output is correct
89 Correct 16 ms 5032 KB Output is correct
90 Correct 15 ms 5156 KB Output is correct
91 Correct 10 ms 5056 KB Output is correct
92 Correct 13 ms 4936 KB Output is correct
93 Correct 25 ms 5132 KB Output is correct
94 Correct 13 ms 5204 KB Output is correct
95 Correct 20 ms 5260 KB Output is correct
96 Correct 19 ms 5164 KB Output is correct
97 Correct 18 ms 5012 KB Output is correct