Submission #103205

# Submission time Handle Problem Language Result Execution time Memory
103205 2019-03-29T08:29:59 Z baluteshih The Big Prize (IOI17_prize) C++14
100 / 100
53 ms 2080 KB
#include "prize.h"
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

pii arr[200005];
map<int,set<int>> lmp,rmp;
pii query(int x)
{
	if(~arr[x].F) return arr[x];
	auto v=ask(x);
	return arr[x]=MP(v[0],v[1]);
}

void insl(int a)
{
	pii t=query(a);
	auto p=lmp[t.F+t.S].upper_bound(a);
	if(p!=lmp[t.F+t.S].end()&&query(*p)==t) 
		lmp[t.F+t.S].erase(p);
	if(p!=lmp[t.F+t.S].begin()&&query(*(--p))==t)
		return;
	lmp[t.F+t.S].insert(a);
}

void insr(int a)
{
	pii t=query(a);
	auto p=rmp[t.F+t.S].lower_bound(a);
	if(p!=rmp[t.F+t.S].end()&&query(*p)==t) 
		return;
	if(p!=rmp[t.F+t.S].begin()&&query(*(--p))==t)
		rmp[t.F+t.S].erase(p);
	rmp[t.F+t.S].insert(a);
}

int search(int l,int r)
{
	if(r-l<=1) return -1;
	int m=l+r>>1;
	pii a=query(l),b=query(r),t=query(m);
	if(t==MP(0,0)) return m;
	auto p=lmp[t.F+t.S].lower_bound(m);
	if(p!=lmp[t.F+t.S].begin())
	{
		--p;
		if(query(*p)==t&&*p<=l) return search(m,r);
	}
	p=rmp[t.F+t.S].upper_bound(m);
	if(p!=rmp[t.F+t.S].end())
	{
		if(query(*p)==t&&*p>=r) return search(l,m);
	}
	insl(m),insr(m);
	if(t==a||!t.F) return search(m,r);
	if(t==b||!t.S) return search(l,m);
	int df=search(l,m);
	if(~df) return df;
	return search(m,r);
}

int find_best(int n) 
{
	fill(arr,arr+n,MP(-1,-1));
	if(query(0)==MP(0,0)) return 0;
	if(query(n-1)==MP(0,0)) return n-1;
	insl(0),insr(n-1);
	return search(0,n-1);
}

Compilation message

prize.cpp: In function 'int search(int, int)':
prize.cpp:51:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m=l+r>>1;
        ~^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2048 KB Output is correct
2 Correct 4 ms 2040 KB Output is correct
3 Correct 7 ms 2040 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 2 ms 1788 KB Output is correct
6 Correct 4 ms 1840 KB Output is correct
7 Correct 5 ms 1808 KB Output is correct
8 Correct 4 ms 1856 KB Output is correct
9 Correct 5 ms 1848 KB Output is correct
10 Correct 4 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1860 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 6 ms 1928 KB Output is correct
4 Correct 4 ms 1792 KB Output is correct
5 Correct 3 ms 1792 KB Output is correct
6 Correct 5 ms 1792 KB Output is correct
7 Correct 5 ms 1920 KB Output is correct
8 Correct 3 ms 2048 KB Output is correct
9 Correct 4 ms 1792 KB Output is correct
10 Correct 3 ms 1920 KB Output is correct
11 Correct 7 ms 1912 KB Output is correct
12 Correct 3 ms 1912 KB Output is correct
13 Correct 6 ms 2076 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 2080 KB Output is correct
16 Correct 42 ms 1848 KB Output is correct
17 Correct 4 ms 1784 KB Output is correct
18 Correct 36 ms 1912 KB Output is correct
19 Correct 4 ms 1792 KB Output is correct
20 Correct 7 ms 1232 KB Output is correct
21 Correct 19 ms 1788 KB Output is correct
22 Correct 8 ms 1792 KB Output is correct
23 Correct 5 ms 1912 KB Output is correct
24 Correct 5 ms 1848 KB Output is correct
25 Correct 25 ms 1992 KB Output is correct
26 Correct 22 ms 1932 KB Output is correct
27 Correct 5 ms 2040 KB Output is correct
28 Correct 39 ms 1912 KB Output is correct
29 Correct 16 ms 1920 KB Output is correct
30 Correct 40 ms 1908 KB Output is correct
31 Correct 5 ms 1848 KB Output is correct
32 Correct 7 ms 1784 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 20 ms 1912 KB Output is correct
35 Correct 5 ms 2044 KB Output is correct
36 Correct 15 ms 1932 KB Output is correct
37 Correct 4 ms 1912 KB Output is correct
38 Correct 3 ms 2048 KB Output is correct
39 Correct 23 ms 1844 KB Output is correct
40 Correct 44 ms 1916 KB Output is correct
41 Correct 29 ms 1904 KB Output is correct
42 Correct 13 ms 1908 KB Output is correct
43 Correct 24 ms 1832 KB Output is correct
44 Correct 20 ms 1980 KB Output is correct
45 Correct 8 ms 1956 KB Output is correct
46 Correct 3 ms 1916 KB Output is correct
47 Correct 22 ms 1840 KB Output is correct
48 Correct 41 ms 1896 KB Output is correct
49 Correct 7 ms 1784 KB Output is correct
50 Correct 33 ms 1932 KB Output is correct
51 Correct 20 ms 1784 KB Output is correct
52 Correct 5 ms 1832 KB Output is correct
53 Correct 4 ms 1912 KB Output is correct
54 Correct 17 ms 1912 KB Output is correct
55 Correct 4 ms 1920 KB Output is correct
56 Correct 39 ms 1784 KB Output is correct
57 Correct 29 ms 1784 KB Output is correct
58 Correct 19 ms 1944 KB Output is correct
59 Correct 24 ms 1920 KB Output is correct
60 Correct 19 ms 1848 KB Output is correct
61 Correct 4 ms 1848 KB Output is correct
62 Correct 4 ms 1784 KB Output is correct
63 Correct 5 ms 1920 KB Output is correct
64 Correct 4 ms 2040 KB Output is correct
65 Correct 4 ms 1912 KB Output is correct
66 Correct 3 ms 1840 KB Output is correct
67 Correct 5 ms 1784 KB Output is correct
68 Correct 5 ms 1784 KB Output is correct
69 Correct 5 ms 1784 KB Output is correct
70 Correct 5 ms 1784 KB Output is correct
71 Correct 41 ms 1920 KB Output is correct
72 Correct 7 ms 1792 KB Output is correct
73 Correct 34 ms 1936 KB Output is correct
74 Correct 19 ms 2004 KB Output is correct
75 Correct 5 ms 1792 KB Output is correct
76 Correct 34 ms 1920 KB Output is correct
77 Correct 28 ms 1892 KB Output is correct
78 Correct 8 ms 1920 KB Output is correct
79 Correct 15 ms 2080 KB Output is correct
80 Correct 33 ms 1912 KB Output is correct
81 Correct 26 ms 1888 KB Output is correct
82 Correct 53 ms 1920 KB Output is correct
83 Correct 4 ms 1920 KB Output is correct
84 Correct 37 ms 1912 KB Output is correct
85 Correct 44 ms 1912 KB Output is correct
86 Correct 9 ms 1920 KB Output is correct
87 Correct 5 ms 2080 KB Output is correct
88 Correct 5 ms 1976 KB Output is correct
89 Correct 9 ms 1920 KB Output is correct
90 Correct 4 ms 1792 KB Output is correct
91 Correct 5 ms 1812 KB Output is correct
92 Correct 4 ms 1920 KB Output is correct
93 Correct 7 ms 1792 KB Output is correct
94 Correct 7 ms 1792 KB Output is correct
95 Correct 7 ms 1792 KB Output is correct
96 Correct 7 ms 1920 KB Output is correct
97 Correct 7 ms 1792 KB Output is correct