Submission #249877

# Submission time Handle Problem Language Result Execution time Memory
249877 2020-07-16T08:20:17 Z hohohaha Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 259960 KB
//	ZapZu's code hohoho
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ln 2*id
#define rn 2*id+1

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int a[1000005];
struct it
{
	vi mx, mx_inv; vt<vi> arr; int n, re, cur_mx;
	it(int _n): n(_n)
	{
		mx.assign(4*n+5, 0);
		mx_inv.assign(4*n+5, 0);
		arr.assign(4*n+5, vi());
	}
	void build(int id, int l, int r)
	{
		if(l==r)
		{
			mx[id] = a[l];
			mx_inv[id] = 0;
			arr[id].eb(a[l]);
			return;
		}
		build(ln, l, (l+r)/2);
		build(rn, (l+r)/2+1, r);
		mx[id] = max(mx[ln], mx[rn]); arr[id].resize(r-l+1); mx_inv[id] = max(mx_inv[2*id], mx_inv[2*id+1]);
		for(int i=0; i<arr[rn].size(); i++) if(arr[rn][i]<mx[ln])mx_inv[id] = max(mx_inv[id],mx[ln]+arr[rn][i]);
		int p1=-1, p2=-1;
		while(p1+1<arr[ln].size() || p2+1<arr[rn].size())
		{
			if(p2+1>=arr[rn].size()) 
			{
				arr[id][p1+p2+2] = arr[ln][p1+1]; //w?
				p1++;
			}
			else if(p1+1>=arr[ln].size())
			{
				arr[id][p1+p2+2] = arr[rn][p2+1];
				p2++;
			}
			else if(arr[ln][p1+1]<arr[rn][p2+1])
			{
				arr[id][p1+p2+2] = arr[ln][p1+1]; //w?
				p1++;
			}
			else 
			{
				arr[id][p1+p2+2] = arr[rn][p2+1];
				p2++;
			}
		}
	}
	void g(int id, int l, int r, int ll, int rr)
	{
		if(ll>r or l>rr) return;
		if(ll<=l and r<=rr)
		{
			re = max(re, mx_inv[id]);
			int lb = 0, rb = arr[id].size()-1;
			while(lb<rb)
			{
				int mid = (lb+rb+1)/2;
				if(arr[id][mid]<cur_mx) lb=mid;
				else rb=mid-1;
			}
			if(arr[id][lb]<cur_mx) re = max(re, cur_mx+arr[id][lb]);
			cur_mx = max(cur_mx, mx[id]);
		}
		else 
		{
			g(ln, l, (l+r)/2, ll, rr);
			g(rn, (l+r)/2+1, r, ll, rr);
		}
	}
	int query(int l, int r)
	{
		re=0; cur_mx=0;
		g(1, 1, n, l, r);
		return re;
	}
} IT(1);
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	fastio;
	int n, q; cin>>n>>q; IT = it(n);
	for(int i=1; i<=n; i++)	cin>>a[i];
	IT.build(1, 1, n);
	while(q--)
	{
		int l, r, k;
		cin>>l>>r>>k;
		if(IT.query(l, r)>k) cout<<0;
		else cout<<1;
		cout<<endl;
	}
}


Compilation message

sortbooks.cpp: In member function 'void it::build(int, int, int)':
sortbooks.cpp:68:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<arr[rn].size(); i++) if(arr[rn][i]<mx[ln])mx_inv[id] = max(mx_inv[id],mx[ln]+arr[rn][i]);
                ~^~~~~~~~~~~~~~~
sortbooks.cpp:70:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(p1+1<arr[ln].size() || p2+1<arr[rn].size())
         ~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:70:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(p1+1<arr[ln].size() || p2+1<arr[rn].size())
                                ~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:72:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(p2+1>=arr[rn].size()) 
       ~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:77:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if(p1+1>=arr[ln].size())
            ~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 12 ms 1408 KB Output is correct
14 Correct 17 ms 1536 KB Output is correct
15 Correct 18 ms 1536 KB Output is correct
16 Correct 15 ms 1536 KB Output is correct
17 Correct 14 ms 1280 KB Output is correct
18 Correct 17 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3107 ms 259960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 419 ms 25200 KB Output is correct
2 Correct 385 ms 24956 KB Output is correct
3 Correct 403 ms 25208 KB Output is correct
4 Correct 388 ms 24952 KB Output is correct
5 Correct 396 ms 24952 KB Output is correct
6 Correct 361 ms 25080 KB Output is correct
7 Correct 375 ms 24952 KB Output is correct
8 Correct 355 ms 24952 KB Output is correct
9 Correct 248 ms 632 KB Output is correct
10 Correct 341 ms 24952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 12 ms 1408 KB Output is correct
14 Correct 17 ms 1536 KB Output is correct
15 Correct 18 ms 1536 KB Output is correct
16 Correct 15 ms 1536 KB Output is correct
17 Correct 14 ms 1280 KB Output is correct
18 Correct 17 ms 1536 KB Output is correct
19 Correct 909 ms 50532 KB Output is correct
20 Correct 903 ms 50428 KB Output is correct
21 Correct 827 ms 50424 KB Output is correct
22 Correct 826 ms 50424 KB Output is correct
23 Correct 831 ms 50680 KB Output is correct
24 Correct 823 ms 50424 KB Output is correct
25 Correct 766 ms 50552 KB Output is correct
26 Correct 874 ms 50420 KB Output is correct
27 Correct 873 ms 50476 KB Output is correct
28 Correct 862 ms 50424 KB Output is correct
29 Correct 892 ms 50424 KB Output is correct
30 Correct 873 ms 50552 KB Output is correct
31 Correct 898 ms 50456 KB Output is correct
32 Correct 913 ms 50424 KB Output is correct
33 Correct 892 ms 50424 KB Output is correct
34 Correct 771 ms 50424 KB Output is correct
35 Correct 763 ms 50552 KB Output is correct
36 Correct 752 ms 50552 KB Output is correct
37 Correct 742 ms 50368 KB Output is correct
38 Correct 775 ms 50424 KB Output is correct
39 Correct 826 ms 50424 KB Output is correct
40 Correct 692 ms 33144 KB Output is correct
41 Correct 741 ms 50424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 12 ms 1408 KB Output is correct
14 Correct 17 ms 1536 KB Output is correct
15 Correct 18 ms 1536 KB Output is correct
16 Correct 15 ms 1536 KB Output is correct
17 Correct 14 ms 1280 KB Output is correct
18 Correct 17 ms 1536 KB Output is correct
19 Execution timed out 3107 ms 259960 KB Time limit exceeded
20 Halted 0 ms 0 KB -