이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int inf=1e9;
const int mod2=998244353;
const int mod1=998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c,d,e;
};
int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,l,r,mid;
int i,s10,s12;
int kk;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
// fin(task),fou(task);
#endif
NHP
/// cin>>s1;
// modwwe
phongbeo();
}
int a[200001];
int ans[1000001];
int c[200001];
int b[200001];
vector<ib> v[200001];
bool d[200001];
struct IT
{
int t[800001];
void upd(int node,int l,int r,int l1,int x)
{
if(l==r)
{
t[node]+=x;
return;
}
int mid=l+r>>1;
if(l1<=mid) upd(node<<1,l,mid,l1,x);
else upd(node<<1|1,mid+1,r,l1,x);
t[node]=t[node<<1]+t[node<<1|1];
}
int get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return 0;
if(l>=l1&&r<=r1) return t[node];
int mid=l+r>>1;
return get(node<<1,l,mid,l1,r1)+get(node<<1|1,mid+1,r,l1,r1);
}
ib bs(int x)
{
int l=1;
int r=n-1;
while(l<=r)
{
int mid=l+r>>1;
if(get(1,1,n,1,mid)>=x) r=mid-1;
else l=mid+1;
}
return {x-get(1,1,n,1,r),r+1};
}
} st;
void go(int x,int y)
{
while(x<y&&!d[x])
{
if(x+b[x]>=y)
st.upd(1,1,n,a[x],y-x);
else st.upd(1,1,n,a[x],b[x]);
d[x]=1;
x+=b[x];
}
}
void phongbeo()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
cin>>a[i],c[a[i]]=i;
for(int i=1; i<=m; i++)
{
cin>>l>>r;
if(l>n)l=n;
if(l==0)ans[i]=a[r];
else v[l].pb({r,i});
}
stack<int> s;
for(int i=1; i<=n/2; i++)
{
while(!s.empty()&&a[s.top()]<a[i])b[s.top()]=i-s.top(),s.pop();
s.push(i);
}
while(!s.empty())b[s.top()]=n/2-s.top()+1,s.pop();
for(int i=n/2+1; i<=n; i++)
{
while(!s.empty()&&a[s.top()]<a[i])b[s.top()]=i-s.top(),s.pop();
s.push(i);
}
while(!s.empty())b[s.top()]=n-s.top()+1,s.pop();
for(int i=1; i<=n/2; i++)
{
if(a[i]>s2) s2=a[i],st.upd(1,1,n,a[i],b[i]),d[i]=1;
}
s2=0;
for(int i=n/2+1; i<=n; i++)
if(a[i]>s2) s2=a[i],st.upd(1,1,n,a[i],b[i]),d[i]=1;
s2=0;
for(int i=1; i<=n; i++)
{
if(i>=2)
{
ib x=st.bs(n/2);
s3=x.b;
s4=st.get(1,1,n,s3,s3);
s5=s4;
s4=s4-x.a;
if(s4!=0)
{
st.upd(1,1,n,s3,-s4);
go(c[s3]+x.a,c[s3]+s5);
}
}
for(auto x:v[i])
{
s8=x.b;
x=st.bs(x.a);
ans[s8]=a[c[x.b]+x.a-1];
}
}
for(int i=1; i<=m; i++)
cout<<ans[i],down
}
/**
10 1
7 5 2 9 10 8 4 3 6 1
2 3
*/
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main()
| ^~~~
Main.cpp: In member function 'void IT::upd(int, int, int, int, int)':
Main.cpp:77:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
77 | int mid=l+r>>1;
| ~^~
Main.cpp: In member function 'int IT::get(int, int, int, int, int)':
Main.cpp:86:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
86 | int mid=l+r>>1;
| ~^~
Main.cpp: In member function 'ib IT::bs(int)':
Main.cpp:95:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
95 | int mid=l+r>>1;
| ~^~
# | 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... |