Submission #390559

# Submission time Handle Problem Language Result Execution time Memory
390559 2021-04-16T10:12:05 Z mehrdad_sohrabi The Big Prize (IOI17_prize) C++14
100 / 100
85 ms 11436 KB
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=2e5+100;
/*
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;
vector<int32_t> ask(int i) {
	query_count++;
	if(query_count > max_q) {
		cerr << "Query limit exceeded" << endl;
		exit(0);
	}

	if(i < 0 || i >= n) {
		cerr << "Bad index: " << i << endl;
		exit(0);
	}

	vector<int32_t> res(2);
	res[0] = rank_count[g[i] - 1][i + 1];
	res[1] = rank_count[g[i] - 1][n] - res[0];
	return res;
}
*/
ll fen[N];
void add(ll idx,ll val){
    for (;idx<N;idx+=idx & -(idx)){
        fen[idx]+=val;
    }
}
ll get(ll idx){
    ll s=0;
    for (;idx;idx-=idx & (-idx)){
        s+=fen[idx];
    }
    return s;
}
ll val[N];
pii a[N];
ll mx=0;
pii ASK(int i){
    if (val[i]==-1){
        vector <int32_t> ans=ask(i);
        a[i]={ans[0],ans[1]};
        val[i]=a[i].F+a[i].S;
    }
    return a[i];
}
ll vis[N];
ll aaa=-1;
void solve(ll l,ll r,ll kl,ll kr){
    if (kl+kr+(get(r)-get(l))>=mx || aaa!=-1) return ;
    vector <int> cand;
    for (int i=l;i<r;i++){
        if (vis[i]){
            cout << 1/0;
        }
        cand.pb(i);
    }
    ll s=cand.size();
    s/=2;
    if (cand.size()==0) return ;
    if (cand.size()==1){

        ASK(cand[0]);
        if (val[cand[0]]<mx){
            vis[cand[0]]=1;

        }
     //   if (val[cand[0]]>mx) cout << 1/0;
        return ;
    }
    ll mid=cand[s-1]+1;
    ll p1=0,p2=0;
    for (int i=s;i<cand.size();i++){
        if (aaa!=-1) return ;
        ASK(cand[i]);
        if (val[cand[i]]<mx){
            vis[cand[i]]=1;
            if (val[cand[i]]==0) aaa=cand[i];
            if (a[cand[i]].F==0) p1=0;
            if (a[cand[i]].S==0) p2=0;
            continue;
        }
        if (val[cand[i]]>mx) cout << 1/0;
        if (i!=cand.size()-1 && p1==0){
            solve(cand[i+1],r,a[cand[i]].F,kr);
        }
        if (p2==0)
        solve(l,mid,kl,a[cand[i]].S+i-s);
        return ;
    }
    if (aaa!=-1 || p1==1) return ;
    solve(l,mid,kl,kr+cand.size()-s);
}
int32_t find_best(int32_t n) {
	memset(val,-1,sizeof val);
	vector <int> rnd;
	for (int i=0;i<n;i++){
        rnd.pb(i);
	}
	random_shuffle(rnd.begin(),rnd.end());
	/*
	if (n>1000){
        ll s=0;
        ll K=500;
        for (int i=s;i<s+K;i++){
            ASK(i);
            mx=max(mx,val[i]);
            if (val[i]==0) return i;
        }
        ll tt=0;
        for (int i=0;i<K;i++){
            if (val[i]!=mx) tt++;
        }
        solve(K,n,tt,0);

	}
	else{
    */
    ll kk=448;
	for (int i=0;i<min((ll)n,kk);i++){
        ASK(rnd[i]);
        mx=max(mx,val[rnd[i]]);
        if (val[rnd[i]]==0) return rnd[i];
        if (val[rnd[i]]>50){
            kk=i+1;
            break;
        }
	}
	for (int i=0;i<min((ll)n,kk);i++){
        if (val[rnd[i]]!=mx){
            add(rnd[i]+1,1);
        }
	}
	solve(0,n,0,0);

	for (int i=0;i<n;i++){
        if (vis[i]==1 && val[i]==0) return i;
	}
	return 0;
}
/*
int32_t main() {
	cin >> n;

	g.resize(n);
	for(int i = 0; i < n; i++) {
		//cin >> g[i];
		g[i]=2;
		if(g[i] < 1) {
			cerr << "Invalid rank " << g[i] << " at index " << i << endl;
			exit(0);
		}
	}
    ll z=rand()%n;
    g[z]=1;
    cout << z << endl;
	int max_rank = *max_element(g.begin(), g.end());

	rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
	for(int r = 0; r <= max_rank; r++) {
		for(int i = 1; i <= n; i++) {
			rank_count[r][i] = rank_count[r][i - 1];
			if(g[i - 1] == r)
			  rank_count[r][i]++;
		}
	}

	for(int i = 0; i <= n; i++)
		for(int r = 1; r <= max_rank; r++)
			rank_count[r][i] += rank_count[r - 1][i];

	int res = find_best(n);
	cout << res << endl << "Query count: " << query_count << endl;

	return 0;
}
*/
/*
8
3 2 3 1 3 3 2 3
*/

Compilation message

prize.cpp: In function 'void solve(ll, ll, ll, ll)':
prize.cpp:72:22: warning: division by zero [-Wdiv-by-zero]
   72 |             cout << 1/0;
      |                     ~^~
prize.cpp:91:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (int i=s;i<cand.size();i++){
      |                  ~^~~~~~~~~~~~
prize.cpp:101:39: warning: division by zero [-Wdiv-by-zero]
  101 |         if (val[cand[i]]>mx) cout << 1/0;
      |                                      ~^~
prize.cpp:102:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         if (i!=cand.size()-1 && p1==0){
      |             ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 8240 KB Output is correct
2 Correct 18 ms 8204 KB Output is correct
3 Correct 14 ms 8180 KB Output is correct
4 Correct 14 ms 8228 KB Output is correct
5 Correct 13 ms 7940 KB Output is correct
6 Correct 18 ms 8204 KB Output is correct
7 Correct 15 ms 7856 KB Output is correct
8 Correct 17 ms 7856 KB Output is correct
9 Correct 17 ms 8120 KB Output is correct
10 Correct 14 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 8120 KB Output is correct
2 Correct 15 ms 8196 KB Output is correct
3 Correct 14 ms 8192 KB Output is correct
4 Correct 16 ms 8124 KB Output is correct
5 Correct 16 ms 7796 KB Output is correct
6 Correct 18 ms 8176 KB Output is correct
7 Correct 15 ms 7856 KB Output is correct
8 Correct 13 ms 7964 KB Output is correct
9 Correct 15 ms 8204 KB Output is correct
10 Correct 19 ms 8256 KB Output is correct
11 Correct 22 ms 8600 KB Output is correct
12 Correct 27 ms 8780 KB Output is correct
13 Correct 17 ms 8208 KB Output is correct
14 Correct 13 ms 2752 KB Output is correct
15 Correct 65 ms 10636 KB Output is correct
16 Correct 22 ms 7604 KB Output is correct
17 Correct 79 ms 11404 KB Output is correct
18 Correct 66 ms 11436 KB Output is correct
19 Correct 68 ms 11352 KB Output is correct
20 Correct 24 ms 5768 KB Output is correct
21 Correct 44 ms 9804 KB Output is correct
22 Correct 67 ms 10524 KB Output is correct
23 Correct 23 ms 8296 KB Output is correct
24 Correct 28 ms 8560 KB Output is correct
25 Correct 54 ms 8408 KB Output is correct
26 Correct 71 ms 10412 KB Output is correct
27 Correct 21 ms 8332 KB Output is correct
28 Correct 61 ms 10340 KB Output is correct
29 Correct 76 ms 10048 KB Output is correct
30 Correct 74 ms 11360 KB Output is correct
31 Correct 80 ms 11312 KB Output is correct
32 Correct 29 ms 8748 KB Output is correct
33 Correct 2 ms 1864 KB Output is correct
34 Correct 43 ms 10028 KB Output is correct
35 Correct 18 ms 8236 KB Output is correct
36 Correct 65 ms 10284 KB Output is correct
37 Correct 25 ms 8496 KB Output is correct
38 Correct 23 ms 8356 KB Output is correct
39 Correct 31 ms 9372 KB Output is correct
40 Correct 11 ms 6844 KB Output is correct
41 Correct 42 ms 8816 KB Output is correct
42 Correct 42 ms 8712 KB Output is correct
43 Correct 42 ms 8948 KB Output is correct
44 Correct 55 ms 9616 KB Output is correct
45 Correct 68 ms 10268 KB Output is correct
46 Correct 62 ms 11308 KB Output is correct
47 Correct 77 ms 10512 KB Output is correct
48 Correct 32 ms 8092 KB Output is correct
49 Correct 55 ms 11144 KB Output is correct
50 Correct 12 ms 6788 KB Output is correct
51 Correct 65 ms 11372 KB Output is correct
52 Correct 50 ms 11396 KB Output is correct
53 Correct 14 ms 8200 KB Output is correct
54 Correct 46 ms 9484 KB Output is correct
55 Correct 82 ms 11436 KB Output is correct
56 Correct 11 ms 6800 KB Output is correct
57 Correct 62 ms 11364 KB Output is correct
58 Correct 81 ms 11308 KB Output is correct
59 Correct 42 ms 8740 KB Output is correct
60 Correct 43 ms 9004 KB Output is correct
61 Correct 16 ms 8116 KB Output is correct
62 Correct 23 ms 8356 KB Output is correct
63 Correct 21 ms 8368 KB Output is correct
64 Correct 20 ms 8280 KB Output is correct
65 Correct 19 ms 8112 KB Output is correct
66 Correct 14 ms 6880 KB Output is correct
67 Correct 17 ms 6804 KB Output is correct
68 Correct 12 ms 6764 KB Output is correct
69 Correct 16 ms 6808 KB Output is correct
70 Correct 14 ms 6848 KB Output is correct
71 Correct 82 ms 11336 KB Output is correct
72 Correct 26 ms 8764 KB Output is correct
73 Correct 67 ms 11296 KB Output is correct
74 Correct 48 ms 11200 KB Output is correct
75 Correct 23 ms 8360 KB Output is correct
76 Correct 58 ms 10992 KB Output is correct
77 Correct 48 ms 11232 KB Output is correct
78 Correct 25 ms 8796 KB Output is correct
79 Correct 53 ms 9892 KB Output is correct
80 Correct 78 ms 11420 KB Output is correct
81 Correct 83 ms 11260 KB Output is correct
82 Correct 45 ms 11208 KB Output is correct
83 Correct 22 ms 8436 KB Output is correct
84 Correct 57 ms 10960 KB Output is correct
85 Correct 85 ms 11276 KB Output is correct
86 Correct 27 ms 9468 KB Output is correct
87 Correct 19 ms 8500 KB Output is correct
88 Correct 26 ms 9340 KB Output is correct
89 Correct 26 ms 9444 KB Output is correct
90 Correct 16 ms 8380 KB Output is correct
91 Correct 22 ms 8468 KB Output is correct
92 Correct 23 ms 9332 KB Output is correct
93 Correct 26 ms 9904 KB Output is correct
94 Correct 25 ms 9920 KB Output is correct
95 Correct 26 ms 9904 KB Output is correct
96 Correct 25 ms 9940 KB Output is correct
97 Correct 17 ms 9580 KB Output is correct