QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184682 | #6733. Moniphant Sleep | bulijiojiodibuliduo# | WA | 612ms | 24788kb | C++ | 3.7kb | 2023-09-21 04:17:32 | 2023-09-21 04:17:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=501000;
int n,q;
struct node {
int ming,maxg;
int tag,mtag;
int atag;
}nd[4*N];
void upd(int p) {
nd[p].ming=min(nd[p+p].ming,nd[p+p+1].ming);
nd[p].maxg=max(nd[p+p].maxg,nd[p+p+1].maxg);
}
void setf(int p,int v1,int v2) {
nd[p].tag+=v1;
nd[p].ming+=v1; nd[p].maxg+=v1;
nd[p].mtag+=v2;
if (nd[p].maxg==nd[p].ming) nd[p].maxg+=v2;
nd[p].ming+=v2;
}
void seta(int p,int v) {
nd[p].atag+=v;
}
void build(int p,int l,int r) {
nd[p].ming=nd[p].maxg=-1;
if (l==r) {
} else {
int md=(l+r)>>1;
build(p+p,l,md);
build(p+p+1,md+1,r);
upd(p);
}
}
void push(int p) {
if (nd[p].tag||nd[p].mtag) {
int v1=nd[p+p].ming,v2=nd[p+p+1].ming;
setf(p+p,nd[p].tag,(v1<=v2)?nd[p].mtag:0);
setf(p+p+1,nd[p].tag,(v2<=v1)?nd[p].mtag:0);
nd[p].tag=nd[p].mtag=0;
}
if (nd[p].atag) {
seta(p+p,nd[p].atag);
seta(p+p+1,nd[p].atag);
nd[p].atag=0;
}
}
int query(int p,int l,int r,int tl,int tr) {
if (tl==l&&tr==r) return nd[p].ming;
else {
push(p);
int md=(l+r)>>1;
if (tr<=md) return query(p+p,l,md,tl,tr);
else if (tl>md) return query(p+p+1,md+1,r,tl,tr);
else return min(query(p+p,l,md,tl,md),query(p+p+1,md+1,r,md+1,tr));
}
}
int qr(int p,int l,int r,int x) {
if (l==r) return nd[p].atag;
else {
push(p);
int md=(l+r)>>1;
if (x<=md) return qr(p+p,l,md,x);
else return qr(p+p+1,md+1,r,x);
}
}
void modify(int p,int l,int r,int tl,int tr,int v1,int v2) {
if (tl>tr) return;
if (tl==l&&tr==r) return setf(p,v1,v2),seta(p,v1);
else {
push(p);
int md=(l+r)>>1;
if (tr<=md) modify(p+p,l,md,tl,tr,v1,v2);
else if (tl>md) modify(p+p+1,md+1,r,tl,tr,v1,v2);
else modify(p+p,l,md,tl,md,v1,v2),modify(p+p+1,md+1,r,md+1,tr,v1,v2);
upd(p);
}
}
void clear(int p,int l,int r,int tl,int tr) {
if (tl>tr) return;
if (tl==l&&tr==r) {
if (nd[p].ming==nd[p].maxg) {
if (nd[p].ming>=0) seta(p,-nd[p].ming);
setf(p,-1-nd[p].ming,0);
} else {
assert(l!=r);
push(p);
int md=(l+r)>>1;
if (tr<=md) clear(p+p,l,md,tl,tr);
else if (tl>md) clear(p+p+1,md+1,r,tl,tr);
else clear(p+p,l,md,tl,md),clear(p+p+1,md+1,r,md+1,tr);
upd(p);
}
} else {
push(p);
int md=(l+r)>>1;
if (tr<=md) clear(p+p,l,md,tl,tr);
else if (tl>md) clear(p+p+1,md+1,r,tl,tr);
else clear(p+p,l,md,tl,md),clear(p+p+1,md+1,r,md+1,tr);
upd(p);
}
}
int main() {
//freopen("A.in","r",stdin);
scanf("%d%d",&n,&q);
build(1,1,n);
rep(i,0,q) {
int op,l,r;
scanf("%d%d%d",&op,&l,&r);
if (op==1) {
int d=query(1,1,n,l,r);
if (d>=0) modify(1,1,n,l,r,1,0);
else modify(1,1,n,l,r,1,-1);
} else if (op==2) {
int d=query(1,1,n,l,r);
if (d>=0) modify(1,1,n,l,r,-1,0);
else modify(1,1,n,l,r,-1,1);
} else if (op==3) {
int d=query(1,1,n,l,r);
if (d==-1) modify(1,1,n,l,r,0,1);
} else if (op==4) {
clear(1,1,n,l,r);
} else {
printf("%d\n",qr(1,1,n,l)+500000);
}
//printf("?? %d %d %d\n",nd[1].tag,nd[1].mtag,query(1,1,n,1,n));
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3692kb
input:
1 9 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 1 1 1 1 1 1 4 1 1 5 1 1
output:
500004
result:
ok 1 number(s): "500004"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
3 7 2 1 3 3 1 3 1 1 3 1 1 3 5 1 1 4 1 3 5 1 1
output:
500001 499999
result:
ok 2 number(s): "500001 499999"
Test #3:
score: -100
Wrong Answer
time: 612ms
memory: 24788kb
input:
500000 500000 2 132991 371170 5 15281 15281 1 278642 397098 2 152103 176573 2 13797 47775 3 139320 370045 3 79054 432340 3 82556 212775 4 270171 469418 5 148000 148000 3 371255 401414 5 71051 71051 2 358945 473071 2 231663 265401 2 20243 58131 1 247710 313373 5 154549 154549 1 17317 233265 5 37602 3...
output:
500000 499999 500000 499998 499999 500000 500001 499997 500000 499997 499997 500000 499998 500000 499998 500000 500001 500001 500000 500000 499997 499998 499997 499998 500000 500001 500002 499996 499998 499999 499998 499998 500002 500000 500002 500004 500004 499999 500001 499999 499997 499999 500006...
result:
wrong answer 7th numbers differ - expected: '500000', found: '500001'