답안 #659035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659035 2022-11-16T03:45:55 Z dkblossom Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
2271 ms 134244 KB
#include<bits/stdc++.h>
using namespace std;

#pragma gcc optimize("ofast")

#define nn '\n'
#define ll long long
#define pb emplace_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ff first
#define ss second

const ll maxn = 1000005;
const ll maxm = 1000005;
const ll mod = 100000000000000007;
const ll inf = mod*2;

struct BIT{
	int arr[maxn];
	int n;

	BIT(int k){
		n = k;
		for(int i=1;i<=n;i++) arr[i] = 0;
	}

	void modify(int x, int pos){
		for(int i=pos;i<=n;i+=i&-i) arr[i] = max(arr[i],x);
	}

	int query(int pos){
		int res = 0;
		for(int i=pos;i>0;i-=i&-i) res = max(res,arr[i]);
		return res;
	}
};

struct query{
	int r, x, pos;
	query(int a, int b, int c):r(a),x(b),pos(c){}
};

int main(){
	int n, q;
	int arr[maxn];
	vector<query> que[maxn];
	int ans[maxn];
	int a, b, c;
	vector<pii> mod[maxn];
	
	cin >> n >> q;

	for(int i=1;i<=n;i++) cin >> arr[i];

	for(int i=1;i<=q;i++){
		cin >> a >> b >> c;
		que[a].pb(query(b,c,i));
	}

	vector<int> stk;
	for(int i=1;i<=n;i++){
		while(stk.size() && arr[stk.back()]<arr[i]) stk.pop_back();
		if(stk.size()) mod[stk.back()].pb(make_pair(i,arr[i]+arr[stk.back()]));
		stk.pb(i);
	}

	BIT bit(n);

	for(int i=n;i>0;i--){
		for(auto k:mod[i]) bit.modify(k.ss,k.ff);
		for(auto k:que[i]) ans[k.pos] = bit.query(k.r)<=k.x;
	}

	for(int i=1;i<=q;i++) cout << ans[i] << nn;
}

Compilation message

sortbooks.cpp:4: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    4 | #pragma gcc optimize("ofast")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 58956 KB Output is correct
2 Correct 35 ms 58992 KB Output is correct
3 Correct 34 ms 58912 KB Output is correct
4 Correct 33 ms 58940 KB Output is correct
5 Correct 34 ms 58964 KB Output is correct
6 Correct 34 ms 58956 KB Output is correct
7 Correct 33 ms 58964 KB Output is correct
8 Correct 34 ms 58968 KB Output is correct
9 Correct 34 ms 58896 KB Output is correct
10 Incorrect 34 ms 58984 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 58956 KB Output is correct
2 Correct 35 ms 58992 KB Output is correct
3 Correct 34 ms 58912 KB Output is correct
4 Correct 33 ms 58940 KB Output is correct
5 Correct 34 ms 58964 KB Output is correct
6 Correct 34 ms 58956 KB Output is correct
7 Correct 33 ms 58964 KB Output is correct
8 Correct 34 ms 58968 KB Output is correct
9 Correct 34 ms 58896 KB Output is correct
10 Incorrect 34 ms 58984 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2271 ms 133176 KB Output is correct
2 Correct 1763 ms 134244 KB Output is correct
3 Correct 1734 ms 134176 KB Output is correct
4 Correct 1750 ms 134192 KB Output is correct
5 Incorrect 1636 ms 115780 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 157 ms 65272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 58956 KB Output is correct
2 Correct 35 ms 58992 KB Output is correct
3 Correct 34 ms 58912 KB Output is correct
4 Correct 33 ms 58940 KB Output is correct
5 Correct 34 ms 58964 KB Output is correct
6 Correct 34 ms 58956 KB Output is correct
7 Correct 33 ms 58964 KB Output is correct
8 Correct 34 ms 58968 KB Output is correct
9 Correct 34 ms 58896 KB Output is correct
10 Incorrect 34 ms 58984 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 58956 KB Output is correct
2 Correct 35 ms 58992 KB Output is correct
3 Correct 34 ms 58912 KB Output is correct
4 Correct 33 ms 58940 KB Output is correct
5 Correct 34 ms 58964 KB Output is correct
6 Correct 34 ms 58956 KB Output is correct
7 Correct 33 ms 58964 KB Output is correct
8 Correct 34 ms 58968 KB Output is correct
9 Correct 34 ms 58896 KB Output is correct
10 Incorrect 34 ms 58984 KB Output isn't correct
11 Halted 0 ms 0 KB -