이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long pogolem[1000000];
long long niza[1000000];
long long drvo[2500000];
long long p;
long long update(long long l,long long r,long long poz,long long k)
{
if (p<l || r<p) return drvo[poz];
if (l==r)
{
drvo[poz] = max(drvo[poz],k);
return drvo[poz];
}
long long mid = (l+r)/2;
drvo[poz] = max(update(l,mid,poz*2,k),update(mid+1,r,poz*2+1,k));
return drvo[poz];
}
long long najdi(long long l,long long r,long long poz,long long levo,long long desno)
{
if (levo<=l && r<=desno) return drvo[poz];
if (r<levo || desno<l) return 0;
long long mid = (l+r)/2;
return max(najdi(l,mid,poz*2,levo,desno),najdi(mid+1,r,poz*2+1,levo,desno));
}
int main()
{
long long n,q;
cin>>n>>q;
long long ns = 1;
while (ns<n) ns*=2;
stack<long long> s;
for (long long i=0;i<n;i++)
{
long long a;
cin>>a;
niza[i] = a;
while(s.size() && niza[s.top()]<=a) s.pop();
if (s.size()) pogolem[i] = s.top();
else pogolem[i] = -1;
s.push(i);
}
/*
cout<<"pogolem: ";
for (long long i=0;i<n;i++)
cout<<pogolem[i]<<" ";
cout<<endl;
*/
vector<tuple<long long,long long,long long> > pras;
for (long long i=0;i<q;i++)
{
long long a,b,c;
cin>>a>>b>>c;
//a--;
//b--;
pras.push_back({b,a,c});
}
sort(pras.begin(),pras.end());
long long t = 0;
for (long long i=0;i<n;i++)
{
if (pogolem[i]!=-1)
{
p = pogolem[i];
update(1,ns,1,niza[i]+niza[p]);
}
while(t<pras.size() && get<0>(pras[t])-1==i)
{
long long x = najdi(1,ns,1, get<1>(pras[t]),get<0>(pras[t]));
if (x<=get<2>(pras[t])) cout<<1<<endl;
else cout<<0<<endl;
t++;
//cout<< "x = "<<x<<endl;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:78:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | while(t<pras.size() && get<0>(pras[t])-1==i)
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |