提出 #70277094
ソースコード 拡げる
//# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include"atcoder/all"
using namespace atcoder;
typedef modint998244353 mi;
using namespace std;
#define all(a) a.begin(),a.end()
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
#define compress(a) sort(all(a));a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
constexpr ll mod=998244353;
constexpr ll inf=3e18;
struct S{
ll pos,lr;
};
struct F{
ll pos,lr;
bool operator==(const F &rhs) const{
return pos==rhs.pos&&lr==rhs.lr;
}
};
const F ID={inf,-1};
S op(S a,S b){if(a.pos<b.pos)return a;return b;}
S e(){return {inf,-1};}
S mapping(F f,S x){return (f==ID?x:S({f.pos,f.lr}));}
F composition(F f,F g){return (f==ID?g:f);};
F id(){return ID;}
int main(){
int n;
cin>>n;
vector<ll>w(n);
rep(i,n)cin>>w[i];
vector<S>V(n,{0,0});
lazy_segtree<S,op,e,F,mapping,composition,id> seg(V);
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==1){
int v;
cin>>v;
auto it=seg.get(v-1);
ll pos_l;
if(it.lr==0)pos_l=it.pos;
else pos_l=it.pos-w[v-1];
seg.apply(0,v,{pos_l,0});
}
else if(t==2){
int v;
cin>>v;
auto it=seg.get(v-1);
ll pos_r;
if(it.lr==0)pos_r=it.pos+w[v-1];
else pos_r=it.pos;
seg.apply(0,v,{pos_r,1});
}
else{
ll x;
cin>>x;
int lb=-1,ub=n;
while(ub-lb>1){
int mi=(ub+lb)/2;
auto it=seg.get(mi);
ll li,ri;
if(it.lr==0){
li=it.pos;
ri=li+w[mi];
}
else{
ri=it.pos;
li=ri-w[mi];
}
if(li<=x&&x<ri){
ub=mi;
}
else lb=mi;
}
cout<<n-ub<<endl;
}
}
}
提出情報
提出日時 |
|
問題 |
F - Pyramid Alignment |
ユーザ |
Rho17 |
言語 |
C++ 20 (gcc 12.2) |
得点 |
525 |
コード長 |
1928 Byte |
結果 |
AC |
実行時間 |
554 ms |
メモリ |
20204 KiB |
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
525 / 525 |
結果 |
|
|
セット名 |
テストケース |
Sample |
00-sample-01.txt |
All |
00-sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, max-01.txt, max-02.txt, max-03.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
00-sample-01.txt |
AC |
1 ms |
3728 KiB |
01-01.txt |
AC |
270 ms |
19504 KiB |
01-02.txt |
AC |
226 ms |
19308 KiB |
01-03.txt |
AC |
265 ms |
12200 KiB |
01-04.txt |
AC |
389 ms |
20044 KiB |
01-05.txt |
AC |
393 ms |
20120 KiB |
01-06.txt |
AC |
406 ms |
20084 KiB |
01-07.txt |
AC |
395 ms |
20052 KiB |
01-08.txt |
AC |
324 ms |
20052 KiB |
01-09.txt |
AC |
328 ms |
20052 KiB |
01-10.txt |
AC |
318 ms |
19672 KiB |
01-11.txt |
AC |
330 ms |
20068 KiB |
01-12.txt |
AC |
328 ms |
19764 KiB |
max-01.txt |
AC |
554 ms |
20124 KiB |
max-02.txt |
AC |
175 ms |
20204 KiB |
max-03.txt |
AC |
150 ms |
20140 KiB |