제출 #779724

#제출 시각아이디문제언어결과실행 시간메모리
779724epicci23Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
64 / 100
539 ms262144 KiB
#include "bits/stdc++.h"
#pragma optimize ("Bismillahirrahmanirrahim")
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl "\n" 
#define int long long
#define double long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what_is(x) cerr << #x << " is " << x << endl;
#define m (l+r)/2
constexpr int N=1000005;
constexpr int MOD=1000000007;
constexpr int  INF2 = LLONG_MAX;
constexpr int INF=(int)1e18;
constexpr int LOG=30;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
typedef priority_queue<pii,vector<pii>,greater<pii>> min_pq;
typedef priority_queue<pii> max_pq;
typedef long long ll;
//to think//
/*
 * graph approach
 * dp
 * dividing the problem to smaller statements
 * finding the real constraint
 * sqrt decomposition
 * greedy approach
 * pigeonhole principle
 * rewriting the problem/equality 
 * bitwise approaches
 * binary search if monotonic
 * divide and conquer
 * combinatorics
 * inclusion - exclusion
 * think like bfs
*/



inline int in()
{
  int x;cin >> x;
  return x;
}

inline string in2()
{
  string x;cin >> x;
  return x;
}

vector<int> seg[4*N];
int ans[4*N];
int ar[N];
int n,q;
int maxi=0;
vector<int> xd;
void build(int rt,int l,int r)
{
  if(l==r) {seg[rt].pb(ar[l]);return;}
  build(rt*2,l,m);build(rt*2+1,m+1,r);
  ans[rt]=max(ans[rt*2],ans[rt*2+1]);
  int it=lower_bound(all(seg[rt*2+1]),seg[rt*2].back())-seg[rt*2+1].begin();
  if(it) ans[rt]=max(seg[rt*2].back()+seg[rt*2+1][it-1],ans[rt]);
  
  int n1=sz(seg[rt*2]),m1=sz(seg[rt*2+1]);
  int p1=0,p2=0;
  while(p1<n1 && p2<m1)
  {
    if(seg[rt*2][p1]<=seg[rt*2+1][p2]) seg[rt].pb(seg[rt*2][p1++]);
    else seg[rt].pb(seg[rt*2+1][p2++]);
  }
  while(p1<n1) seg[rt].pb(seg[rt*2][p1++]);
  while(p2<m1) seg[rt].pb(seg[rt*2+1][p2++]);
}

void query(int rt,int l,int r,int gl,int gr)
{
  if(r<gl || l>gr || l>r) return;
  if(l>=gl && r<=gr)
  {
    maxi=max(maxi,ans[rt]);
    xd.pb(rt);
    return;
  } 
  query(rt*2,l,m,gl,gr);query(rt*2+1,m+1,r,gl,gr);
}


void solve()
{
  n=in(),q=in();
  for(int i=1;i<=n;i++) ar[i]=in();
  build(1,1,n);

  while(q--)
  {
    maxi=0;
    xd.clear();
    int l=in(),r=in(),zo=in();
    query(1,1,n,l,r);
    int hm=0;
    for(int i=0;i<sz(xd)-1;i++)
    {
      hm=max(hm,seg[xd[i]].back());
      int it=lower_bound(all(seg[xd[i+1]]),hm)-seg[xd[i+1]].begin();
      if(it) maxi=max(hm+seg[xd[i+1]][it-1],maxi);
    }

    if(maxi<=zo) cout << 1 << endl;
    else cout << 0 << endl;
  }
} 

int32_t main(){
   

     cin.tie(0); ios::sync_with_stdio(0);
     cout << fixed <<  setprecision(15);
   
   int t=1;//cin>> t;
 
 for(int i=1;i<=t;i++)
 {
  //  cout << "Case #" << i << ": ";
    solve();
 }
 
 return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize ("Bismillahirrahmanirrahim")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...