T3 求调,12:00 之前调成功悬一袋红烧牛肉面
#include<bits/stdc++.h>
#define Type int
#define qr(x) x=read()
typedef long long ll;
using namespace std;
inline Type read(){
char c=getchar(); Type x=0;
while(!isdigit(c))c=getchar();
while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int n, q, f[N];
char s[N];
int P(char A, char B){
if(A == '#' or B == '@') return 1;
if(A == B) return 0;
if(A == 'R'){
if(B == 'S') return 1;
else return -1;
}
else if(A == 'S'){
if(B == 'P') return 1;
else return -1;
}
else{
if(B == 'R') return 1;
else return -1;
}
}
struct tree{
int v, pos, tag;
bool operator < (const tree &A) const{
return v < A.v;
}
}t[N<<3];
namespace Tree
{
#define lson rt<<1
#define rson rt<<1|1
inline void pushup(int rt){
if(t[lson].v < t[rson].v) t[rt].v = t[lson].v, t[rt].pos = t[lson].pos;
else t[rt].v = t[rson].v, t[rt].pos = t[rson].pos;
}
inline void pushdown(int rt){
if(t[rt].tag){
t[lson].tag += t[rt].tag, t[rson].tag += t[rt].tag;
t[lson].v += t[rt].tag, t[rson].v += t[rt].tag;
t[rt].tag = 0;
}
}
inline void build(int rt, int l, int r){
if(l == r){
t[rt].v = f[l], t[rt].pos = l;
return;
}
int mid = (l + r) >> 1;
build(lson, l, mid),
build(rson, mid+1, r);
pushup(rt);
// if(t[rt].pos == 0) cout<<"CTHisSB\n";
}
inline void update(int rt, int l, int r, int pos, int val){
if(pos <= l and r <= n){
t[rt].tag += val, t[rt].v += val;
return;
}pushdown(rt);
int mid = (l + r) >> 1;
if(pos <= mid) update(lson, l, mid, pos, val);
if(n > mid) update(rson, mid+1, r, pos, val);
pushup(rt);
}
inline tree query(int rt, int l, int r, int L, int R){
if(L <= l and r <= R) return t[rt];
pushdown(rt);
int mid = (l + r) >> 1;
if(R <= mid) return query(lson, l, mid, L, R);
else{
if(L > mid) return query(rson, mid+1, r, L, R);
else return min(query(lson, l, mid, L, R), query(rson, mid+1, r, L, R));
}
}
}
signed main(){
freopen("a.in", "r", stdin), freopen("a.out", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
qr(n), qr(q), cin>>(s+1);
f[1] = 1; s[0] = '#', s[n+1] = '@';
for(int i=2; i<=n; i++)
f[i] = f[i-1] + P(s[i-1], s[i]);
Tree::build(1, 1, n);
while(q--)
{
int qr(op);
switch(op){
case 1:{int qr(p); char c; cin>>c; int now = P(s[p-1], c) - P(s[p-1], s[p]);
Tree::update(1, 1, n, p, now); now = P(c, s[p+1]) - P(s[p], s[p+1]);
Tree::update(1, 1, n, p+1, now); s[p] = c; break; }
default:{int qr(l), qr(r); cout<<s[Tree::query(1, 1, n, l, r).pos]<<"\n"; break;}
}
}
return 0;
}
为了方便判断,我让 s[0]='#'
,但交到 oj 上却输出了这个:
显然是返回了 0,但是毫无缘由,代码里注释部分是输出树上所有点的 pos
,结果没有为 0 的。