QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647254 | #7449. rgxsxrs | lichenghan | 0 | 4ms | 36444kb | C++14 | 4.6kb | 2024-10-17 13:02:37 | 2024-10-17 13:02:38 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO {
int ow;
const int olim=(1<<21)-30;
char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<21];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read() {
int x=0; char c=gc();
while(!isdigit(c)) c=gc();
while(isdigit(c)) x=x*10+(c^48),c=gc();
return x;
}
inline void flush() {
fwrite(obuf,ow,1,stdout),ow=0;
}
inline void write(ll x) {
if(!x) obuf[ow++]='0';
else {
int t=ow;
for(;x;x/=10) obuf[ow++]=(x%10)^48;
reverse(obuf+t,obuf+ow);
}
if(ow>=olim) flush();
}
inline void putc(const char &c) {
obuf[ow++]=c;
if(ow>=olim) flush();
}
#undef gc
}
const int N=5e5+10;
const int D=16,pw[8]={1, 16, 256, 4096, 65536, 1048576, 16777216, 268435456};
const int B=32;
const int inf=1e9;
inline constexpr int vblk(const int& x){ return __lg(x)>>2; }
inline constexpr void chkmax(int& x,const int& y){ if(y>x) x=y; }
inline constexpr void chkmin(int& x,const int& y){ if(y<x) x=y; }
bool _Mst;
int n,m,a[N];
int stk[N],top;
struct SEGT{
int b[N],lower;
struct node {
ll sum;
int cnt,maxn,minn,lz;
inline void push(const int& x){
cnt++;
sum+=x;
chkmax(maxn,x);
chkmin(minn,x);
}
}t[N>>2];
void psu(int p){
node& u=t[p],l=t[p<<1],r=t[p<<1|1];
u.cnt=l.cnt+r.cnt;
u.sum=l.sum+r.sum;
u.maxn=max(l.maxn,r.maxn);
u.minn=min(l.minn,r.minn);
}
void blk_psu(int l,int r,int p){
t[p]={0,0,-inf,inf,0};
for(int i=l;i<=r;i++) if(b[i]!=-1) t[p].push(b[i]);
}
void blk_adt(int l,int r,int p,int d){
for(int i=l;i<=r;i++) if(b[i]!=-1) b[i]-=d;
}
void adt(int p,int d){
node& u=t[p];
u.sum-=(ll)u.cnt*d;
u.maxn-=d; u.minn-=d;
u.lz+=d;
}
void psd(int p){
if(t[p].lz){
adt(p<<1,t[p].lz);
adt(p<<1|1,t[p].lz);
t[p].lz=0;
}
}
void build(int l,int r,int p,auto f){
// printf("build %d %d %d\n",l,r,p);
if(r-l<B){
for(int i=l;i<=r;i++){
b[i]=f(i);
}
blk_psu(l,r,p);
return;
}
int mid=(l+r)>>1;
build(l,mid,p<<1,f);
build(mid+1,r,p<<1|1,f);
psu(p);
}
void dec(int l,int r,int p,int tl,int tr,int d){
if(t[p].maxn<=d) return;
if(r-l<B){
blk_adt(l,r,p,t[p].lz);
t[p].lz=0;
for(int i=tl;i<=tr;i++) if(b[i]>d) {
b[i]-=d;
if(b[i]<lower){
a[i]=b[i];
b[i]=-1;
stk[++top]=i;
}
}
blk_psu(l,r,p);
return;
}
if(l==tl&&r==tr&&t[p].minn>=lower+d) return adt(p,d);
int mid=(l+r)>>1; psd(p);
if(tr<=mid) dec(l,mid,p<<1,tl,tr,d);
else if(tl>mid) dec(mid+1,r,p<<1|1,tl,tr,d);
else dec(l,mid,p<<1,tl,mid,d),dec(mid+1,r,p<<1|1,mid+1,tr,d);
psu(p);
}
void insert(int l,int r,int p,int x,int d){
if(r-l<B){
blk_adt(l,r,p,t[p].lz);
t[p].lz=0;
b[x]=d;
blk_psu(l,r,p);
return;
}
int mid=(l+r)>>1; psd(p);
if(x<=mid) insert(l,mid,p<<1,x,d);
else insert(mid+1,r,p<<1|1,x,d);
psu(p);
}
ll ressum;
int resmin,resmax;
void q(int l,int r,int p,int tl,int tr){
if(r-l<B){
blk_adt(l,r,p,t[p].lz);
t[p].lz=0;
for(int i=tl;i<=tr;i++) if(b[i]!=-1){
ressum+=b[i];
chkmin(resmin,b[i]);
chkmax(resmax,b[i]);
}
return;
}
if(l==tl&&r==tr) {
ressum+=t[p].sum;
chkmin(resmin,t[p].minn);
chkmax(resmax,t[p].maxn);
return;
}
int mid=(l+r)>>1; psd(p);
if(tr<=mid) q(l,mid,p<<1,tl,tr);
else if(tl>mid) q(mid+1,r,p<<1|1,tl,tr);
else q(l,mid,p<<1,tl,mid),q(mid+1,r,p<<1|1,mid+1,tr);
}
void build(auto f){
build(1,n,1,f);
}
void dec(int l,int r,int d){
dec(1,n,1,l,r,d);
}
void insert(int x,int d){
insert(1,n,1,x,d);
}
array<ll,3> query(int l,int r){
ressum=0; resmin=inf; resmax=-inf;
q(1,n,1,l,r);
return {ressum,resmin,resmax};
}
}T[8];
bool _Med;
int main(){
for(int i=0;i<8;i++) T[i].lower=pw[i];
n=IO::read(); m=IO::read();
for(int i=1;i<=n;i++) a[i]=IO::read();
for(int i=0;i<8;i++) T[i].build([&](int x){ return vblk(a[x])==i?a[x]:-1; });
int lstans=0;
while(m--){
int op,l,r,d;
op=IO::read(); l=IO::read(); r=IO::read();
// l^=lstans; r^=lstans;
if(op==1){
d=IO::read();
top=0;
for(int i=0;i<8;i++) T[i].dec(l,r,d);
for(int i=1;i<=top;i++){
int u=stk[i];
// printf("drop! a[%d] = %d\n",u,a[u]);
T[vblk(a[u])].insert(u,a[u]);
}
}else{
ll x=0;
int y=inf,z=-inf;
for(int i=0;i<8;i++){
auto [u,v,w]=T[i].query(l,r);
x+=u; chkmin(y,v); chkmax(z,w);
}
IO::write(x); IO::putc(' ');
IO::write(y); IO::putc(' ');
IO::write(z); IO::putc('\n');
lstans=x&((1<<20)-1);
}
}
IO::flush();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 36444kb
input:
1000 1000 935816535 513713699 701239859 881761843 312245068 749043434 112422339 4851733 369182510 741607986 336173081 76013815 91837056 23042507 28754006 935721035 332487169 739344582 280604892 549629633 428486579 693745524 772744523 736620619 596867287 553364838 842666116 620926490 350404590 972861...
output:
265016378473 746807 999055631 0 0 0 0 1000000000
result:
wrong answer 4th numbers differ - expected: '666065535', found: '0'
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
200000 200000 10 7 6 1 5 5 10 1 9 4 7 1 5 4 8 9 5 7 10 2 10 3 3 5 5 2 1 4 10 5 7 2 6 1 3 1 6 4 7 5 3 1 3 2 9 5 4 10 8 3 10 4 4 8 5 4 6 10 4 10 9 6 7 4 6 7 7 6 2 6 6 10 10 6 8 8 9 4 6 3 3 9 8 1 8 5 8 2 7 3 1 10 5 10 1 5 8 5 6 6 7 9 7 3 5 8 4 4 3 2 9 3 10 2 5 4 2 2 6 3 3 5 8 4 2 1 2 9 2 3 6 3 8 9 4 10...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded
input:
200000 200000 615 736 846 534 658 429 631 720 898 583 797 295 303 336 449 358 57 338 954 414 330 212 171 200 403 553 308 20 805 249 767 291 545 196 324 928 439 197 20 601 737 748 817 858 816 130 403 858 813 936 771 242 833 863 978 260 357 856 954 89 673 733 364 473 903 445 823 894 49 747 382 56 309 ...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #8:
score: 0
Time Limit Exceeded
input:
200000 200000 78066 141247 11068 105207 26127 179253 104948 145839 150954 60877 67556 61673 69638 150806 127596 162902 125410 38242 97645 20582 193537 139906 114184 129867 126626 85640 91551 19445 134855 85251 22162 3798 122992 38278 131907 96159 153440 94561 185234 15296 76886 108452 70560 77355 14...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #12:
score: 0
Time Limit Exceeded
input:
500000 500000 56 22353719 15918 54 13 1 389 7 809 2204 75911688 4218278 36 7205 93542078 506 4761175 102646343 48 65900 10 228 2 292994 26348644 6 19339 148 704 232124395 19307 52070 8964343 7430314 42755 115 869 32485365 252183868 481162087 852632 38758 2945883 279412 15012 82 33076951 1537 6954898...
output:
106593480756