답안 #1072096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072096 2024-08-23T14:18:46 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 85388 KB
#include <bits/stdc++.h>
#define int long long
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
const int N=1e6+1;
const int inf=1e18;
const int mod=1e9+7;
using namespace std;
struct edge{
	int l,k,id;
};
vector<edge>v1[N];
vector<int>v;
int t[4*N];
void upd(int n,int tl,int tr,int pos,int x){
	if(tl==tr){
		t[n]=x;
		return;
	}
	int mid=(tl+tr)/2;
	upd(n*2,tl,mid,pos,x);
	upd(n*2+1,mid+1,tr,pos,x);
	t[n]=max(t[n*2],t[n*2+1]);
}
int get(int n,int tl,int tr,int l,int r){
	if(tr<l||r<tl){
		return 0;
	}
	if(l<=tl&&tr<=r){
		return t[n];
	}
	int mid=(tl+tr)/2;
	return max(get(n*2,tl,mid,l,r),get(n*2+1,mid+1,tr,l,r));
}
stack<pair<int,int> >st;
int ans[N];
signed main(){
	boost;
	int n,m;
	cin>>n>>m;
	v.push_back(0);
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		v.push_back(x);
	}
	for(int i=1;i<=m;i++){
		int l,r,k;
		cin>>l>>r>>k;
		edge x;
		x.l=l;
		x.k=k;
		x.id=i;
		v1[r].push_back(x);
	}
	for(int i=1;i<=n;i++){
		if(v1[i].size()>0){
		while(st.size()>0&&st.top().first<v[i]){
			st.pop();
		}
		if(st.size()>0){
			upd(1,1,n,st.top().second,st.top().first+v[i]);
			st.pop();
		}
		}
	for(int j=0;j<v1[i].size();j++){
		ans[v1[i][j].id]=(get(1,1,n,v1[i][j].l,i)<=v1[i][j].k);
	}	
	st.push({v[i],i});
	}
	for(int i=1;i<=m;i++){
		cout<<ans[i]<<"\n";
	}
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:66:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for(int j=0;j<v1[i].size();j++){
      |              ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25944 KB Output is correct
2 Correct 9 ms 25944 KB Output is correct
3 Incorrect 10 ms 25888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25944 KB Output is correct
2 Correct 9 ms 25944 KB Output is correct
3 Incorrect 10 ms 25888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3051 ms 85388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 32836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25944 KB Output is correct
2 Correct 9 ms 25944 KB Output is correct
3 Incorrect 10 ms 25888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25944 KB Output is correct
2 Correct 9 ms 25944 KB Output is correct
3 Incorrect 10 ms 25888 KB Output isn't correct
4 Halted 0 ms 0 KB -