답안 #161589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161589 2019-11-03T08:04:50 Z MvC Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
77 / 100
3000 ms 15076 KB
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int bk=2000;
const int nmax=1e6+5000;
const int mod=1e9+7;
using namespace std;
int n,m,a[nmax],mx,i,j,l,r,k,mxx,bukmx[nmax/bk],bukmn[nmax/bk],buk[nmax/bk],x,f[nmax],mnn;
vector<int>vc[nmax/bk];
void calc(int l,int r)
{
	int mxx=0,mx=0,mn=inf;
	for(int i=l;i<=r;i++)
	{
		if(a[i]<mx)mxx=max(mxx,a[i]+mx);
		mx=max(mx,a[i]);
		mn=min(mn,a[i]);
		vc[l/bk].pb(a[i]);
	}
	buk[l/bk]=mxx;
	bukmx[l/bk]=mx;
	bukmn[l/bk]=mn;
	sort(vc[l/bk].begin(),vc[l/bk].end());
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=0;i<n;i++)cin>>a[i];
	mnn=inf;
	f[0]=1;
	for(i=1;i<n;i++)
	{
		if(a[i]>=a[i-1])f[i]=f[i-1]+1;
		else f[i]=1;
		mnn=min(mnn,a[i]);
	}
	for(i=0;i<n;i+=bk)
	{
		calc(i,min(i+bk-1,n-1));
	}
	while(m--)
	{
		cin>>l>>r>>k;
		l--,r--;
		if(k<mnn)
		{
			if(f[r]>=r-l+1)cout<<"1\n";
			else cout<<"0\n";
			continue;
		}
		mx=mxx=0;
		for(i=l;i<=r;i++)
		{
			if(i%bk==0)break;
			if(a[i]<mx)mxx=max(mxx,a[i]+mx);
			mx=max(mx,a[i]);
		}
		for(;i+bk<=r;i+=bk)
		{
			mxx=max(mxx,buk[i/bk]);
			if(bukmn[i/bk]<mx)
			{
				x=*(--upper_bound(vc[i/bk].begin(),vc[i/bk].end(),mx-1));
				mxx=max(mxx,mx+x);
			}
			mx=max(mx,bukmx[i/bk]);
		}
		for(;i<=r;i++)
		{
			if(a[i]<mx)mxx=max(mxx,a[i]+mx);
			mx=max(mx,a[i]);
		}
		if(mxx<=k)cout<<"1\n";
		else cout<<"0\n";
	}
	return 0;
}

Compilation message

sortbooks.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
sortbooks.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 7 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 12 ms 504 KB Output is correct
14 Correct 18 ms 568 KB Output is correct
15 Correct 18 ms 504 KB Output is correct
16 Correct 16 ms 504 KB Output is correct
17 Correct 9 ms 504 KB Output is correct
18 Correct 15 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 712 ms 15076 KB Output is correct
2 Correct 722 ms 14316 KB Output is correct
3 Correct 712 ms 14404 KB Output is correct
4 Correct 701 ms 14296 KB Output is correct
5 Correct 664 ms 14320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 418 ms 1984 KB Output is correct
2 Correct 550 ms 1960 KB Output is correct
3 Correct 352 ms 1836 KB Output is correct
4 Correct 342 ms 1912 KB Output is correct
5 Correct 327 ms 1784 KB Output is correct
6 Correct 517 ms 1964 KB Output is correct
7 Correct 493 ms 1912 KB Output is correct
8 Correct 377 ms 2120 KB Output is correct
9 Correct 74 ms 632 KB Output is correct
10 Correct 371 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 7 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 12 ms 504 KB Output is correct
14 Correct 18 ms 568 KB Output is correct
15 Correct 18 ms 504 KB Output is correct
16 Correct 16 ms 504 KB Output is correct
17 Correct 9 ms 504 KB Output is correct
18 Correct 15 ms 504 KB Output is correct
19 Correct 967 ms 3276 KB Output is correct
20 Correct 948 ms 3360 KB Output is correct
21 Correct 1370 ms 3376 KB Output is correct
22 Correct 1343 ms 3356 KB Output is correct
23 Correct 1330 ms 3244 KB Output is correct
24 Correct 759 ms 3256 KB Output is correct
25 Correct 766 ms 3236 KB Output is correct
26 Correct 736 ms 3228 KB Output is correct
27 Correct 742 ms 3320 KB Output is correct
28 Correct 724 ms 3216 KB Output is correct
29 Correct 697 ms 3320 KB Output is correct
30 Correct 694 ms 3220 KB Output is correct
31 Correct 713 ms 3204 KB Output is correct
32 Correct 719 ms 3256 KB Output is correct
33 Correct 754 ms 3416 KB Output is correct
34 Correct 1010 ms 3324 KB Output is correct
35 Correct 1024 ms 3320 KB Output is correct
36 Correct 1102 ms 3212 KB Output is correct
37 Correct 1053 ms 3296 KB Output is correct
38 Correct 1052 ms 3288 KB Output is correct
39 Correct 821 ms 3268 KB Output is correct
40 Correct 538 ms 2364 KB Output is correct
41 Correct 894 ms 3312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 7 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 12 ms 504 KB Output is correct
14 Correct 18 ms 568 KB Output is correct
15 Correct 18 ms 504 KB Output is correct
16 Correct 16 ms 504 KB Output is correct
17 Correct 9 ms 504 KB Output is correct
18 Correct 15 ms 504 KB Output is correct
19 Correct 712 ms 15076 KB Output is correct
20 Correct 722 ms 14316 KB Output is correct
21 Correct 712 ms 14404 KB Output is correct
22 Correct 701 ms 14296 KB Output is correct
23 Correct 664 ms 14320 KB Output is correct
24 Correct 418 ms 1984 KB Output is correct
25 Correct 550 ms 1960 KB Output is correct
26 Correct 352 ms 1836 KB Output is correct
27 Correct 342 ms 1912 KB Output is correct
28 Correct 327 ms 1784 KB Output is correct
29 Correct 517 ms 1964 KB Output is correct
30 Correct 493 ms 1912 KB Output is correct
31 Correct 377 ms 2120 KB Output is correct
32 Correct 74 ms 632 KB Output is correct
33 Correct 371 ms 1876 KB Output is correct
34 Correct 967 ms 3276 KB Output is correct
35 Correct 948 ms 3360 KB Output is correct
36 Correct 1370 ms 3376 KB Output is correct
37 Correct 1343 ms 3356 KB Output is correct
38 Correct 1330 ms 3244 KB Output is correct
39 Correct 759 ms 3256 KB Output is correct
40 Correct 766 ms 3236 KB Output is correct
41 Correct 736 ms 3228 KB Output is correct
42 Correct 742 ms 3320 KB Output is correct
43 Correct 724 ms 3216 KB Output is correct
44 Correct 697 ms 3320 KB Output is correct
45 Correct 694 ms 3220 KB Output is correct
46 Correct 713 ms 3204 KB Output is correct
47 Correct 719 ms 3256 KB Output is correct
48 Correct 754 ms 3416 KB Output is correct
49 Correct 1010 ms 3324 KB Output is correct
50 Correct 1024 ms 3320 KB Output is correct
51 Correct 1102 ms 3212 KB Output is correct
52 Correct 1053 ms 3296 KB Output is correct
53 Correct 1052 ms 3288 KB Output is correct
54 Correct 821 ms 3268 KB Output is correct
55 Correct 538 ms 2364 KB Output is correct
56 Correct 894 ms 3312 KB Output is correct
57 Execution timed out 3019 ms 13728 KB Time limit exceeded
58 Halted 0 ms 0 KB -