結果
問題 | No.878 Range High-Element Query |
ユーザー |
|
提出日時 | 2024-11-30 20:42:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 193 ms / 2,000 ms |
コード長 | 1,029 bytes |
コンパイル時間 | 2,222 ms |
コンパイル使用メモリ | 212,308 KB |
最終ジャッジ日時 | 2025-02-26 09:43:06 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; #include<atcoder/segtree> using namespace atcoder; using S = int; S op(S a, S b){ return a+b; } S e(){ return 0; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,q; cin>>n>>q; vector<int> a(n); rep(i,n)cin>>a[i]; vector<tuple<int,int,int>> qu(q); rep(i,q){ int t,l,r; cin>>t>>l>>r; l--; qu[i]={l,r,i}; } sort(qu.begin(),qu.end(),greater<>()); segtree<S,op,e> seg(n); vector<int> ans(q); stack<pair<int,int>> st; int now=n-1; for(auto [l,r,id]:qu){ while(l<=now){ while(st.size()>=1 && a[now]>st.top().first){ seg.set(st.top().second, 0); st.pop(); } st.push(make_pair(a[now], now)); seg.set(now, 1); now--; } ans[id]=seg.prod(l,r); } rep(i,q)cout<<ans[i]<<endl; }