제출 #863976

#제출 시각아이디문제언어결과실행 시간메모리
863976nnhzzzHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
637 ms75924 KiB
// cre: Nguyen Ngoc Hung - Train VOI 2024 #include<bits/stdc++.h> using namespace std; #define __nnhzzz__ signed main() #define BIT(i,j) ((i>>j)&1LL) #define MASK(i) (1LL<<i) #define ALL(x) (x).begin(),(x).end() #define SZ(x) (int)(x).size() #define gcd __gcd #define fi first #define se second #define ll long long #define ull unsigned long long #define ld long double #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define pii pair<int,int> #define vpii vector<pii> #define REP(i,a,b) for(int i = (a); i<=(b); ++i) #define REPD(i,a,b) for(int i = (a); i>=(b); --i) #define REPDIS(i,a,b,c) for(int i = (a); i<=(b); i+=c) #define endl "\n" #define MP make_pair // #define int ll //-------------------------------------------------------------// const int inf = 1e9+7,LOG = 20,MAXN = 1e6+7,N = 1e2+3; const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353; //-------------------------------------------------------------// template<typename T> bool mini(T &a, const T &b){if(a>b){a=b;return true;}return false;} template<typename T> bool maxi(T &a, const T &b){if(a<b){a=b;return true;}return false;} /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Nguyen Ngoc Hung - nnhzzz Training for VOI24 gold medal ---------------------------------------------------------------- */ using T = tuple<int,int,int>; struct Node{ int val,ma; Node(int x):val(x),ma(0){}; }; Node merge(const Node &a, const Node &b){ Node res = a; int tmp = 0; if(a.ma!=0 && maxi(tmp,a.val+a.ma)){ res.val = a.val; res.ma = a.ma; } if(b.ma!=0 && maxi(tmp,b.val+b.ma)){ res.val = b.val; res.ma = b.ma; } return res; } struct segment_tree{ vector<Node> st; vi lazy; int n; void pushdown(int id, int l, int r){ if(l==r || lazy[id]==0) return ; if(st[id<<1].val>=lazy[id]) maxi(st[id<<1].ma,lazy[id]); if(st[id<<1|1].val>=lazy[id]) maxi(st[id<<1|1].ma,lazy[id]); maxi(lazy[id<<1],lazy[id]); maxi(lazy[id<<1|1],lazy[id]); lazy[id] = 0; } void update(int id, int l, int r, int lo, int hi, int x){ if(l>hi || r<lo) return ; if(l>=lo && r<=hi){ if(st[id].val>=x) maxi(st[id].ma,x); maxi(lazy[id],x); pushdown(id,l,r); return ; } pushdown(id,l,r); int mid = (l+r)>>1; update(id<<1,l,mid,lo,hi,x); update(id<<1|1,mid+1,r,lo,hi,x); st[id] = merge(st[id<<1],st[id<<1|1]); } void add(int id, int l, int r, int pos, int x){ if(l>pos || r<pos) return ; if(l==r){ st[id].val = x; return ; } pushdown(id,l,r); int mid = (l+r)>>1; add(id<<1,l,mid,pos,x); add(id<<1|1,mid+1,r,pos,x); st[id] = merge(st[id<<1],st[id<<1|1]); } int get(int id, int l, int r, int lo, int hi){ if(l>hi || r<lo) return 0; pushdown(id,l,r); if(l>=lo && r<=hi){ if(st[id].ma==0) return 0; return st[id].ma+st[id].val; } int mid = (l+r)>>1; return max(get(id<<1,l,mid,lo,hi),get(id<<1|1,mid+1,r,lo,hi)); } void update(int l, int r, int x){ update(1,1,n,l,r,x); } void add(int pos, int x){ add(1,1,n,pos,x); } int get(int l, int r){ return get(1,1,n,l,r); } segment_tree(int x):n(x){ st.assign(n<<2|1,Node(0)); lazy.assign(n<<2|1,0); } }; struct fenwick_tree{ vi f; int n; void update(int id, int val){ for(; id>0; id-=id&-id) maxi(f[id],val); } int get(int id){ int res = 0; for(; id<=n; id+=id&-id) maxi(res,f[id]); return res; } fenwick_tree(int _n):n(_n){ f.assign(n+3,0); } }; int a[MAXN]; vector<T> adj[MAXN]; int n,q; void sub1(){ while(q--){ int ok = 1,l,r,k; cin >> l >> r >> k; vi b; REP(i,l,r) b.push_back(a[i]); REPD(i,r-l,0){ int ma = 0,pos = 0; REP(j,0,i){ if(maxi(ma,b[j]) || ma==b[j]) pos = j; } while(pos!=i){ if(b[pos]+b[pos+1]<=k){ swap(b[pos],b[pos+1]); ++pos; }else{ ok = 0; break; } } } if(is_sorted(ALL(b)) && ok==1) cout << 1; else cout << 0; cout << endl; } } void sub3(){ vi fre(n+3,n+1); a[n+1] = inf; REPD(i,n,1){ if(a[i]>a[i+1]) fre[i] = i+1; else fre[i] = fre[i+1]; } while(q--){ int l,r,k; cin >> l >> r >> k; if(fre[l]>r) cout << 1; else cout << 0; cout << endl; } } void sub5(){ vi res(q+3,0); REP(i,1,q){ int l,r,k; cin >> l >> r >> k; adj[r].emplace_back(l,k,i); } // segment_tree seg(n); fenwick_tree fen(n+3); stack<int> st; REP(i,1,n){ // if(i>1) seg.update(1,i-1,a[i]); while(SZ(st)!=0 && a[st.top()]<=a[i]) st.pop(); int r = i; for(const auto &it:adj[r]){ int l = get<0>(it),k = get<1>(it),id = get<2>(it); // if(seg.get(l,r)<=k) res[id] = 1; // cerr << seg.get(l,r) << endl; if(fen.get(l)<=k) res[id] = 1; } if(SZ(st)!=0) fen.update(st.top(),a[st.top()]+a[i]); st.push(i); // seg.add(i,a[i]); } REP(i,1,q) cout << res[i] << endl; } void solve(){ cin >> n >> q; REP(i,1,n) cin >> a[i]; sub5(); return ; if(n<=500 && q<=500){ sub1(); return ; } sub5(); } __nnhzzz__{ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "test" if(fopen(name".inp","r")){ freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } #define name1 "nnhzzz" if(fopen(name1".inp","r")){ freopen(name1".inp","r",stdin); freopen(name1".out","w",stdout); } int test = 1; while(test--){ solve(); } cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n"; return 0; }

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

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:238:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  238 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:239:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  239 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:243:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  243 |         freopen(name1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:244:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  244 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...