QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#805792 | #9792. Ogre Sort | ucup-team5008# | WA | 0ms | 3496kb | C++23 | 3.2kb | 2024-12-08 18:36:33 | 2024-12-08 18:36:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const ll inf=LLONG_MAX/4;
#define rep2(i,j,k) for(ll i=ll(j);i<ll(k);i++)
#define rep(i,k) rep2(i,0,k)
#define rrep2(i,j,k) for(ll i=ll(j)-1;i>=ll(k);i--)
#define rrep(i,k) rrep2(i,k,0)
#define eb emplace_back
#define SZ(a) ll(a.size())
#define all(a) a.begin(),a.end()
template<class T>
bool chmin(T& a, T b){return a>b?a=b,1:0;}
template<class T>
bool chmax(T& a, T b){return a<b?a=b,1:0;}
struct lazy_segtree{
using S=ll;
const S e=0;
S op(S l, S r){
return min(inf, l+r);
}
using F=P;
const F id=make_pair(1,0);
F compose(F g, F f){
ll a = min(inf, g.first*f.first);
ll b = min(inf, f.second*g.first+g.second);
if(inf/g.first < f.first) a=inf;
if(inf/g.first < f.second) b=inf;
return make_pair(a,b);
}
S mapping(F f, S x){
ll res = min(inf, x*f.first+f.second);
if(inf/f.first < x) res = inf;
return res;
}
ll n, log;
vector<S> d;
vector<F> lz;
void update(int k){d[k]=op(d[2*k],d[2*k+1]);}
void all_apply(int k,F f){
d[k]=mapping(f,d[k]);
if(k<n) lz[k]=compose(f,lz[k]);
}
void push(int k){
all_apply(2*k,lz[k]);
all_apply(2*k+1,lz[k]);
lz[k]=id;
}
lazy_segtree(vector<S> init){
log=0;
while(1<<log < SZ(init)) log++;
n=1<<log;
d.assign(2*n,e);
lz.assign(n,id);
rep(i,SZ(init)) d[n+i]=init[i];
rrep2(i,n,1) update(i);
}
void apply(int l, int r, F f){
assert(0<=l && l<=r && r<=n);
l+=n;
r+=n;
rrep2(i,log+1,1){
if((l>>i)<<i != l) push(l>>i);
if((r>>i)<<i != r) push(r>>i);
}
{
int l2=l, r2=r;
while(l<r){
if(l&1) all_apply(l++,f);
if(r&1) all_apply(--r,f);
l>>=1;
r>>=1;
}
l=l2;
r=r2;
}
rep2(i,1,log+1){
if((l>>i)<<i != l) update(l>>i);
if((r>>i)<<i != r) update(r>>i);
}
}
S prod(int l, int r){
assert(0<=l && l<=r && r<=n);
l+=n;
r+=n;
rrep2(i,log+1,1){
if((l>>i)<<i != l) push(l>>i);
if((r>>i)<<i != r) push(r>>i);
}
S sl=e, sr=e;
while(l<r){
if(l&1) sl=op(sl,d[l++]);
if(r&1) sr=op(d[--r],sr);
l>>=1;
r>>=1;
}
return op(sl,sr);
}
template<class F>
int max_right(int l, F f){
assert(0<=l && l<=n);
assert(f(e));
if(l == n) return n;
l+=n;
rrep2(i,log+1,1) push(l>>i);
S now=0;
do{
while(-l&1) l>>=1;
if(!f(op(now,d[l]))){
while(l<n){
push(l);
l*=2;
if(f(op(now, d[l]))){
now=op(now,d[l]);
++l;
}
}
return l=n;
}
now=op(now,d[l]);
++l;
}while((l&-l) != l);
return n;
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
ll n,q; cin >> n >> q;
string s; cin >> s;
lazy_segtree seg(vl(n, 1));
auto calc=[&](ll idx){
idx = seg.max_right(0, [&](ll val){ return val <= idx;});
idx--;
return idx;
};
while(q--){
ll t; cin >> t;
if(t==1){
ll l,r; cin>>l>>r;
ll l2=calc(l);
ll r2=calc(r);
if(l2 == r2){
seg.apply(l2, r2+1, make_pair(1, r-l+1));
} else{
ll vl=seg.prod(0, l2+1);
ll vr=seg.prod(0, r2);
seg.apply(l2, l2+1, make_pair(1, vl-l+1));
seg.apply(r2, r2+1, make_pair(1, r-vr));
seg.apply(l2+1, r2, make_pair(2, 0));
}
}else{
ll idx; cin>>idx;
idx=calc(idx);
cout << s[idx] << "\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3496kb
input:
4 1 2 4 3
output:
_
result:
wrong output format Expected integer, but "_" found