Submission #689829

# Submission time Handle Problem Language Result Execution time Memory
689829 2023-01-29T13:23:03 Z Paul_Liao_1457 Fire (JOI20_ho_t5) C++17
100 / 100
753 ms 52908 KB
//記得跳題
#include<iostream>
#include<array>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<tuple>
 
#define ll long long
#define LL __int128_t
#define DB double
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (ll)(1e9)
#define MOD (ll)(1e9+7)
#define F first
#define S second
#define endl "\n"
#define AC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
using namespace std;
 
template<class T> using PQ=priority_queue<T,vector<T>,greater<T> >;
 
void file(){
    freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin);
    freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout);
}

vector<pair<pair<int,int>,ll> >op[200005],query[200005];

ll seg[2][800005],tag[2][800005];

void push(int t,int id,int l,int r){
    if(!tag[t][id]) return;
    int mid=(l+r)>>1;
    seg[t][id<<1]+=tag[t][id]*(mid-l+1);
    seg[t][(id<<1)|1]+=tag[t][id]*(r-mid);
    tag[t][id<<1]+=tag[t][id];
    tag[t][(id<<1)|1]+=tag[t][id];
    tag[t][id]=0;
}

void add(int t,int id,int l,int r,int L,int R,ll v){
    if(l>R||r<L) return;
    if(L<=l&&r<=R){
        seg[t][id]+=v*(r-l+1);
        tag[t][id]+=v;
        return;
    }
    int mid=(l+r)>>1;
    push(t,id,l,r);
    add(t,id<<1,l,mid,L,R,v);
    add(t,(id<<1)|1,mid+1,r,L,R,v);
    seg[t][id]=seg[t][id<<1]+seg[t][(id<<1)|1];
}

ll ask(int t,int id,int l,int r,int L,int R){
    if(l>R||r<L) return 0;
    if(L<=l&&r<=R){
        //if(t==0) cout<<" l="<<l<<" r="<<r<<" val="<<seg[t][id]<<endl;
        return seg[t][id];
    }
    push(t,id,l,r);
    int mid=(l+r)>>1;
    return ask(t,id<<1,l,mid,L,R)+ask(t,(id<<1)|1,mid+1,r,L,R);
}

int n,q;

void add_tri(int l,int r,ll v){
    //cout<<"l="<<l<<" r="<<r<<" v="<<v<<endl;
    add(0,1,1,n,l,n,v);
    if(r+1<=n) add(1,1,1,n,r+1,n,-v);
    op[(r-l+1)].pb({{l,r},v});
}

int s[200005],l[200005],r[200005];
ll ans[200005];

signed main(){
    AC;
    cin>>n>>q;
    FOR(i,1,n+1) cin>>s[i];
    stack<pair<int,int> > st;
    FOR(i,1,n+1){
        while(st.size()&&st.top().F<s[i]){
            st.pop();
        }
        if(!st.size()) l[i]=0;
        else l[i]=st.top().S;
        st.push({s[i],i});
    }
    while(st.size()) st.pop();
    REP(i,n,1){
        while(st.size()&&st.top().F<=s[i]){
            st.pop();
        }
        if(!st.size()) r[i]=n+1;
        else r[i]=st.top().S;
        st.push({s[i],i});
    }
    FOR(i,1,n+1){
        //cout<<"l["<<i<<"]="<<l[i]<<" r["<<i<<"]="<<r[i]<<endl;
        if(!l[i]){
            add(1,1,1,n,i,r[i]-1,s[i]);
            if(i+1<=r[i]-1) add_tri(i+1,r[i]-1,-s[i]);
        }
        else{
            add_tri(l[i]+1,r[i]-1,s[i]);
            if(l[i]+1<=i-1) add_tri(l[i]+1,i-1,-s[i]);
            if(i+1<=r[i]-1) add_tri(i+1,r[i]-1,-s[i]);
        }
    }
    FOR(i,0,q){
        int t,l,r; cin>>t>>l>>r;
        query[t].pb({{l,r},i});
    }
    FOR(i,1,n+1){
        //cout<<"i="<<i<<endl;
        for(auto [a,b]:op[i]){
            //cout<<"b="<<b<<endl;
            add(0,1,1,n,a.F,n,-b);
            if(a.S+1<=n) add(1,1,1,n,a.S+1,n,b);
        }
        for(auto [a,b]:query[i]){
            //cout<<"a="<<a.F<<" "<<a.S<<endl;
            ans[b]=ask(0,1,1,n,a.F-i,a.S-i)+ask(1,1,1,n,a.F,a.S);
            //cout<<"b="<<b<<endl;
            //cout<<ask(0,1,1,n,a.F-i,a.S-i)<<endl;
            //cout<<ask(1,1,1,n,a.F,a.S)<<endl;
        }
    }
    FOR(i,0,q) cout<<ans[i]<<endl;
}

 
/*
 
 */

Compilation message

ho_t5.cpp: In function 'void file()':
ho_t5.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t5.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9812 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9688 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9724 KB Output is correct
10 Correct 6 ms 9716 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9756 KB Output is correct
16 Correct 6 ms 9720 KB Output is correct
17 Correct 6 ms 9720 KB Output is correct
18 Correct 5 ms 9812 KB Output is correct
19 Correct 5 ms 9812 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 5 ms 9748 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 5 ms 9712 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 6 ms 9720 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
29 Correct 5 ms 9812 KB Output is correct
30 Correct 5 ms 9716 KB Output is correct
31 Correct 6 ms 9812 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 616 ms 50748 KB Output is correct
3 Correct 581 ms 48828 KB Output is correct
4 Correct 675 ms 50696 KB Output is correct
5 Correct 645 ms 52828 KB Output is correct
6 Correct 674 ms 50356 KB Output is correct
7 Correct 644 ms 50892 KB Output is correct
8 Correct 664 ms 48856 KB Output is correct
9 Correct 648 ms 49196 KB Output is correct
10 Correct 616 ms 50652 KB Output is correct
11 Correct 611 ms 51188 KB Output is correct
12 Correct 593 ms 50488 KB Output is correct
13 Correct 692 ms 52756 KB Output is correct
14 Correct 670 ms 48684 KB Output is correct
15 Correct 654 ms 52908 KB Output is correct
16 Correct 672 ms 48540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 637 ms 49856 KB Output is correct
3 Correct 608 ms 49344 KB Output is correct
4 Correct 666 ms 50068 KB Output is correct
5 Correct 627 ms 49304 KB Output is correct
6 Correct 634 ms 49556 KB Output is correct
7 Correct 619 ms 49700 KB Output is correct
8 Correct 637 ms 49660 KB Output is correct
9 Correct 617 ms 49408 KB Output is correct
10 Correct 626 ms 49112 KB Output is correct
11 Correct 634 ms 49948 KB Output is correct
12 Correct 621 ms 49644 KB Output is correct
13 Correct 637 ms 49884 KB Output is correct
14 Correct 609 ms 49584 KB Output is correct
15 Correct 631 ms 49748 KB Output is correct
16 Correct 634 ms 49588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 48140 KB Output is correct
2 Correct 588 ms 48044 KB Output is correct
3 Correct 601 ms 48564 KB Output is correct
4 Correct 604 ms 48344 KB Output is correct
5 Correct 601 ms 48120 KB Output is correct
6 Correct 598 ms 47928 KB Output is correct
7 Correct 598 ms 48452 KB Output is correct
8 Correct 605 ms 48328 KB Output is correct
9 Correct 596 ms 48180 KB Output is correct
10 Correct 593 ms 48180 KB Output is correct
11 Correct 599 ms 48488 KB Output is correct
12 Correct 597 ms 48528 KB Output is correct
13 Correct 599 ms 48300 KB Output is correct
14 Correct 608 ms 48328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9812 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9688 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9724 KB Output is correct
10 Correct 6 ms 9716 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9756 KB Output is correct
16 Correct 6 ms 9720 KB Output is correct
17 Correct 6 ms 9720 KB Output is correct
18 Correct 5 ms 9812 KB Output is correct
19 Correct 5 ms 9812 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 5 ms 9748 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 5 ms 9712 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 6 ms 9720 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
29 Correct 5 ms 9812 KB Output is correct
30 Correct 5 ms 9716 KB Output is correct
31 Correct 6 ms 9812 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 616 ms 50748 KB Output is correct
34 Correct 581 ms 48828 KB Output is correct
35 Correct 675 ms 50696 KB Output is correct
36 Correct 645 ms 52828 KB Output is correct
37 Correct 674 ms 50356 KB Output is correct
38 Correct 644 ms 50892 KB Output is correct
39 Correct 664 ms 48856 KB Output is correct
40 Correct 648 ms 49196 KB Output is correct
41 Correct 616 ms 50652 KB Output is correct
42 Correct 611 ms 51188 KB Output is correct
43 Correct 593 ms 50488 KB Output is correct
44 Correct 692 ms 52756 KB Output is correct
45 Correct 670 ms 48684 KB Output is correct
46 Correct 654 ms 52908 KB Output is correct
47 Correct 672 ms 48540 KB Output is correct
48 Correct 637 ms 49856 KB Output is correct
49 Correct 608 ms 49344 KB Output is correct
50 Correct 666 ms 50068 KB Output is correct
51 Correct 627 ms 49304 KB Output is correct
52 Correct 634 ms 49556 KB Output is correct
53 Correct 619 ms 49700 KB Output is correct
54 Correct 637 ms 49660 KB Output is correct
55 Correct 617 ms 49408 KB Output is correct
56 Correct 626 ms 49112 KB Output is correct
57 Correct 634 ms 49948 KB Output is correct
58 Correct 621 ms 49644 KB Output is correct
59 Correct 637 ms 49884 KB Output is correct
60 Correct 609 ms 49584 KB Output is correct
61 Correct 631 ms 49748 KB Output is correct
62 Correct 634 ms 49588 KB Output is correct
63 Correct 595 ms 48140 KB Output is correct
64 Correct 588 ms 48044 KB Output is correct
65 Correct 601 ms 48564 KB Output is correct
66 Correct 604 ms 48344 KB Output is correct
67 Correct 601 ms 48120 KB Output is correct
68 Correct 598 ms 47928 KB Output is correct
69 Correct 598 ms 48452 KB Output is correct
70 Correct 605 ms 48328 KB Output is correct
71 Correct 596 ms 48180 KB Output is correct
72 Correct 593 ms 48180 KB Output is correct
73 Correct 599 ms 48488 KB Output is correct
74 Correct 597 ms 48528 KB Output is correct
75 Correct 599 ms 48300 KB Output is correct
76 Correct 608 ms 48328 KB Output is correct
77 Correct 716 ms 50528 KB Output is correct
78 Correct 722 ms 51140 KB Output is correct
79 Correct 721 ms 50456 KB Output is correct
80 Correct 702 ms 50572 KB Output is correct
81 Correct 696 ms 50480 KB Output is correct
82 Correct 705 ms 50792 KB Output is correct
83 Correct 711 ms 50612 KB Output is correct
84 Correct 711 ms 50644 KB Output is correct
85 Correct 724 ms 50628 KB Output is correct
86 Correct 708 ms 50628 KB Output is correct
87 Correct 628 ms 50832 KB Output is correct
88 Correct 611 ms 50696 KB Output is correct
89 Correct 592 ms 50412 KB Output is correct
90 Correct 615 ms 50672 KB Output is correct
91 Correct 606 ms 50300 KB Output is correct
92 Correct 596 ms 50236 KB Output is correct
93 Correct 609 ms 50408 KB Output is correct
94 Correct 652 ms 51132 KB Output is correct
95 Correct 617 ms 51156 KB Output is correct
96 Correct 602 ms 50348 KB Output is correct
97 Correct 602 ms 50612 KB Output is correct
98 Correct 745 ms 49948 KB Output is correct
99 Correct 748 ms 49860 KB Output is correct
100 Correct 736 ms 50232 KB Output is correct
101 Correct 721 ms 50228 KB Output is correct
102 Correct 753 ms 50784 KB Output is correct