QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375207#8286. Stackswilly109WA 4ms10424kbC++203.8kb2024-04-02 23:36:002024-04-02 23:36:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-02 23:36:01]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10424kb
  • [2024-04-02 23:36:00]
  • 提交

answer

#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define ld long double
#define int long long
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5 + 10, sq = 10 , lg = 19,  mod = 1e9 + 7 , inf = 1e9+10 ;
int A[maxn] , val[maxn] ;

struct nd{
    int l = 0 , r = 0  , j1 =0 , j2 = 0 ,  o = 0 ;
    pii sm ; 
    vector <pii> vec , sf ;
    void bui(int R){
        vec.clear() ;
        sf.clear() ;
        int ls = 0 , sum =0 , mx = 0 ; 
        j1 = j2 =0 ; 
        per(i , R , l){
            sum += A[i] ;
            int ted = max(sum - mx , 0ll) ;
            j1 += ted ;
            j2 += ted * val[i] ;
            mx = max(mx , sum) ;
            if(sz(vec)==0 || vec.back().F < sum){
                if(sz(vec))sf.pb({val[i] * (sum-vec.back().F),(sum-vec.back().F)});
                else sf.pb({val[i]*sum,sum});
                vec.pb({sum , val[i]}) ;
            }
        }
        o = sum ;
        per(i , sz(sf)-2 , 0){
            sf[i].F += sf[i+1].F ;
            sf[i].S += sf[i+1].S ;
        }
    }
    void updsm(int mx , int bl){
        int x = lower_bound(all(vec) , (pii){mx-bl+1 , 0})-vec.begin() ;
        sm = {0,0} ;
        if(x==sz(vec)){
            return; 
        }
        if(x!=sz(vec)-1){
            sm.F += sf[x+1].F ;
            sm.S += sf[x+1].S ; 
        }
        sm.F += (vec[x].F+bl-mx)*vec[x].S ;
        sm.S +=(vec[x].F+bl-mx) ;
    }
    pii que(int a){
        if(a==0)return {a,0} ;
        if(a >= sm.S){
            a-=sm.S;
            return {a,sm.F} ;
        }
        int sm = 0;
        per(i , sz(vec)-1 , 0){
            int t = min(a,max(0ll,vec[i].F-(i==0 ? 0 : vec[i-1].F))) ;
            sm += t*vec[i].S ; 
            a-=t ;
        }        
        return {a,sm} ; 
    }
};
nd s[maxn] ;

int ans[maxn] ;
vector <pair<int,pii> > u[maxn] , qu[maxn] ;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n , q ;
    cin >> n >> q; 
    int cnt= 1 ;
    rep(i , 1, q){
        int t , l , r , x , y ;
        cin >> t ;
        if(t == 1){
            cin >> l >> r >> x >> y ;
            u[l].pb({i , {x,y}}) ;
            u[r+1].pb({i , {0 ,0}}) ;
        }
        if(t == 2){
            int l , r , x ;
            cin >> l >> r >> x ;
            u[l].pb({i , {-x , 0}}) ;
            u[r+1].pb({i , {0, 0}}) ;
        }
        if(t==3){
            int x , a ,b ;
            cin >> x >> a >> b ;
            qu[x].pb({i,{b,cnt}});
            qu[x].pb({i , {a-1,cnt+1}});
            cnt+=2 ;
        }
    }
    rep(i , 1 , q/sq)s[i].l = i*sq; 
    rep(i , 1, n){
        for(auto x : u[i]){
            int t= x.F , a = x.S.F , b = x.S.S ;
            A[t] = a ;
            val[t] = b; 
            s[t/sq].bui(min(q , (t/sq+1)*sq-1)) ;
        }
        for(auto x : qu[i]){
            int t= x.F , a = x.S.F , id = x.S.S ;
            s[t/sq].bui(t); 
            int mx =0 , jm = 0 ; 
            per(j , t/sq, 0){
                s[j].updsm(mx,jm);
                if(sz(s[j].vec))mx=max(mx , jm + s[j].vec.back().F); 
                jm += s[j].o ; 
            }
            int f =0 ;
            rep(j , 0 , t/sq){
                pii x =s[j].que(a) ;  
                f +=  x.S; 
                a= x.F ;
            }
            ans[id] = f ; 
            s[t/sq].bui(min(q , t/sq+sq-1)) ;
        }
    }
    for(int i = 1 ; i < cnt ; i+=2){
        cout << ans[i]-ans[i+1] << "\n" ;
    }
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 10424kb

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
647114751
123945
50793012
61782451
0
0
58379
762429740
0
638060258
536311874
4916719610
0
1792521566
6640518748
2323371588
122249391
225987900
5250788038
1145132507
140071334
0
457983255
3230672310
5646099271
84280112
1232466642
4992966775
81661779...

result:

wrong answer 13th numbers differ - expected: '0', found: '58379'