QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360856 | #8229. 栈 | zzafanti | 0 | 271ms | 49424kb | C++23 | 4.2kb | 2024-03-22 12:14:59 | 2024-03-22 12:14:59 |
Judging History
answer
#ifdef zzafanti
#define _GLIBCXX_DEBUG
#endif // zzafanti
#include<bits/stdc++.h>
using namespace std;
using E=long long;
E sgn(E x){ return x<0?-1:1; }
struct segment{
struct node{
int l,r,fg=0;
E x,lsum,y,val;
node(){
l=r=0,fg=0;
x=y=val=lsum=0;
}
};
/**
* add ()
* query ()
*/
vector<node> tr,mem;
void build(int u,int l,int r){
mem[u].l=tr[u].l=l,mem[u].r=tr[u].r=r;
if(l==r) return ;
int mid=(l+r)>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
}
segment(int sz){
mem=tr=vector<node>(sz*4+12);
if(sz>=1) build(1,1,sz);
}
E calcu(int u,E k){ /// sum of the first k '('
int l=tr[u].l,r=tr[u].r;
if(l==r) return (tr[u].val)*k;
int mid=(l+r)>>1;
if(tr[u<<1].x-tr[u<<1|1].y>=k) return calcu(u<<1,k);
return calcu(u<<1|1,k-max(0ll,(tr[u<<1].x-tr[u<<1|1].y)))+tr[u].lsum;
}
E calcu0(int u,E k){ /// sum of the first k '(' in mem
if(mem[u].fg) return calcu(u,k);
int l=mem[u].l,r=mem[u].r;
if(l==r) return (mem[u].val)*k;
int mid=(l+r)>>1;
if(mem[u<<1].x-mem[u<<1|1].y>=k) return calcu0(u<<1,k);
return calcu0(u<<1|1,k-max(0ll,(mem[u<<1].x-mem[u<<1|1].y)))+mem[u].lsum;
}
void maintain(int u){
int ls=u<<1,rs=u<<1|1;
if(tr[rs].y>=tr[ls].x){
tr[u].y=tr[ls].y+tr[rs].y-tr[ls].x;
tr[u].x=tr[rs].x;
return ;
}
tr[u].lsum=calcu(u<<1,tr[ls].x-tr[rs].y);
tr[u].x=tr[rs].x+tr[ls].x-tr[rs].y;
tr[u].y=tr[ls].y;
}
void maintain0(int u){
int ls=u<<1,rs=u<<1|1;
if(mem[rs].y>=mem[ls].x){
mem[u].y=mem[ls].y+mem[rs].y-mem[ls].x;
mem[u].x=mem[rs].x;
return ;
}
mem[u].lsum=calcu0(u<<1,mem[ls].x-mem[rs].y);
mem[u].x=mem[rs].x+mem[ls].x-mem[rs].y;
mem[u].y=mem[ls].y;
}
void add(int u,int pos,E dx,E ds,E dy){
int l=tr[u].l,r=tr[u].r;
if(l==r){
tr[u].x+=dx;
tr[u].val+=ds;
tr[u].y+=dy;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) add(u<<1,pos,dx,ds,dy);
else add(u<<1|1,pos,dx,ds,dy);
maintain(u);
}
vector<int> stk;
void query(int u,int R,E k){
stk.emplace_back(u);
int l=tr[u].l,r=tr[u].r;
if(r<=R){
mem[u]=tr[u];
mem[u].fg=1;
return ;
}
int mid=(l+r)>>1;
if(R<=mid){
query(u<<1,R,k);
maintain0(u);
return ;
}
query(u<<1,R,k);
query(u<<1|1,R,k);
maintain0(u);
return ;
}
void reset(){
while(stk.size()){
mem[stk.back()]=node();
mem[stk.back()].l=tr[stk.back()].l;
mem[stk.back()].r=tr[stk.back()].r;
stk.pop_back();
}
}
};
constexpr int N=100010;
struct querys{
int op,when;
E l,r;
querys() { op=l=when=r=0; }
querys(int Op=0,int wh=0,E L=0,E R=0) { op=Op,when=wh,l=L,r=R; }
friend bool operator < (const querys &x,const querys &y){
return x.when<y.when;
}
};
vector<querys> oper[N];
int n,m;
int main(){
#ifdef zzafanti
freopen("in.in","r",stdin);
#endif // zzafanti
cin.tie(nullptr),cout.tie(nullptr)->sync_with_stdio(false);
cin>>n>>m;
vector<E> ans(m+1,-1);
for(int i=1; i<=m; i++){
int op,l,r;
E x,y;
cin>>op;
if(op==1){
cin>>l>>r>>x>>y;
oper[l].emplace_back(querys(1,i,x,y));
if(r<n) oper[r+1].emplace_back(querys(-1,i,x,y));
}
if(op==2){
cin>>l>>r>>x;
oper[l].emplace_back(querys(2,i,x,0));
if(r<n) oper[r+1].emplace_back(querys(-2,i,x,0));
}
if(op==3){
cin>>l>>x>>y;
oper[l].emplace_back(querys(3,i,x,y));
}
}
segment S(m);
for(int i=1; i<=n; i++){
sort(oper[i].begin(),oper[i].end());
for(auto pt:oper[i]){
if(abs(pt.op)==1){
S.add(1,pt.when,pt.l*sgn(pt.op),sgn(pt.op)*pt.r,0);
}
if(abs(pt.op)==2){
S.add(1,pt.when,0,0,pt.l*sgn(pt.op));
}
if(pt.op==3){
S.query(1,pt.when,pt.r);
ans[pt.when]=S.calcu0(1,pt.r);
S.reset();
S.query(1,pt.when,pt.l-1);
ans[pt.when]-=S.calcu0(1,pt.l-1);
S.reset();
}
}
}
for(int i=1; i<=m; i++){
if(ans[i]!=-1){
cout<<ans[i]<<'\n';
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 5344kb
input:
4907 4910 2 763 3330 1 3 307 1 1 1 2262 3430 22699 89397 1 1915 4000 51541 67587 2 212 2990 9763 2 1086 2162 1 2 1813 4496 16760 1 51 2796 68005 99390 1 1267 1519 74236 66178 3 1768 23808 54314 2 900 4122 27758 3 3287 17350 28989 2 3277 4024 3633 2 444 4866 1 2 353 4219 1061 1 987 3141 99906 17320 2...
output:
0 3032090730 903396180 471569175 200648623 98486697 4102014651 123945 50793012 61782451 -3454899900 0 0 762429740 321140700 871619914 536311874 5361094892 0 1792521566 11357931598 2415375780 249435711 225987900 5250788038 9159665123 140071334 0 118545795 3086405469 5646099271 84280112 1232466642 499...
result:
wrong answer 7th numbers differ - expected: '647114751', found: '4102014651'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 271ms
memory: 48972kb
input:
99999 99998 1 5026 18575 27178 90423 3 30623 1 1 3 76936 1 1 1 77021 95683 84664 24734 1 46085 74886 40512 11266 3 5048 8594 22468 1 53318 77721 97151 70784 1 70645 91192 37556 13013 1 56752 56940 91812 62887 1 7928 34576 87339 69404 3 74875 32807 100970 3 22338 17221 25771 3 21421 20602 57957 3 717...
output:
0 0 1254619125 4366274868 593473604 2592655824 3657975552 5652513833 110091352 1226646296 1989326852 763582808 20410671941 1659086055 3012598941 20085582585 15350314335 33063695949 28572771569 4722824224 27067502374 899316516 49569427017 988382364 13341823621 11397759491 2449683584 17982790260 80572...
result:
wrong answer 13th numbers differ - expected: '8205318671', found: '20410671941'
Subtask #3:
score: 0
Wrong Answer
Test #12:
score: 0
Wrong Answer
time: 139ms
memory: 49424kb
input:
100000 99993 1 47773 70467 16065 1 2 52349 78446 2304 3 40821 1 1 1 40216 93069 78144 1 1 41089 43671 76025 1 2 35263 68629 31066 3 79881 13534 57327 3 5556 1 1 2 21962 38192 1 1 664 58116 9417 1 3 28089 6039 7989 2 88500 90302 9946 3 63215 49410 60770 2 11069 89527 57581 2 70303 97603 12363 1 3420 ...
output:
0 43794 0 1951 11361 129 898 29245 7969 1947 34972 16405 102386 137744 38615 110643 48615 -11425 32225 37527 -108792 31810 16824 96178 14285 493656 57614 1602 129470 73105 4068 114182 28779 245692 26099 193437 250368 4796 183349 125791 17414 61871 42058 -184498 2698 183297 23029 54464 0 374768 56655...
result:
wrong answer 13th numbers differ - expected: '59952', found: '102386'
Subtask #4:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 163ms
memory: 49312kb
input:
99999 99996 3 77889 1 10000000000 1 6316 86327 89644 386 3 9260 1 10000000000 2 2603 47234 69717 2 20260 73011 19290 2 62477 81233 26127 1 50140 68508 37004 98794 2 14449 22788 16063 1 43860 84932 50375 21777 1 67345 94584 28202 66610 2 661 68654 1 1 14411 94422 82738 61196 1 16563 94416 4920 38408 ...
output:
0 34602584 0 0 31396108121 -9090054905 -6569651280 1902514434 1902514434 11077822459 1902514434 15794375094 -879103405 4192446657 15797478185 13141921145 0 7868536656 7140923427 363222594 10925840686 11123619457 -3789936360 6843261316 6874676097 2843959163 0 15697816065 15564014362 21958753162 29824...
result:
wrong answer 5th numbers differ - expected: '27739639583', found: '31396108121'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%