Submission #536084

# Submission time Handle Problem Language Result Execution time Memory
536084 2022-03-12T09:56:31 Z Rafi22 Fire (JOI20_ho_t5) C++14
1 / 100
400 ms 108440 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=200007;

ll BIT[N];
void ins(int v,ll x)
{
    for(;v>0;v-=(v&-v)) BIT[v]+=x;
}
ll que(int v)
{
    ll res=0;
    for(;v<N;v+=(v&-v)) res+=BIT[v];
    return res;
}
int a[N];
int L[N],R[N];

struct ev
{
    int t,b,l,r,x;
};
bool cmp(ev l,ev r)
{
    if(l.t==r.t) return l.b<r.b;
    return l.t<r.t;
}

ll ans[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    vector<pair<int,int>>S;
    S.pb({inf,n+1});
    for(int i=n;i>0;i--)
    {
        while(S.back().st<=a[i]) S.pop_back();
        R[i]=S.back().nd-1;
        S.pb({a[i],i});
    }
    S.clear();
    S.pb({inf,-n});
    for(int i=1;i<=n;i++)
    {
        while(S.back().st<i) S.pop_back();
        L[i]=S.back().nd;
        S.pb({R[i],i});
    }
    vector<ev>E1,E2;
    for(int i=1;i<=n;i++)
    {
        int t=i-L[i]-1,d=R[i]-i+1;
        if(d<=t)
        {
            for(int j=i;j<=R[i];j++)
            {
                E1.pb({j,0,j-i,j-i+t,a[i]});
            }
        }
        else
        {
            for(int j=0;j<=t;j++)
            {
                E2.pb({i-j,0,j,j+d-1,a[i]});
            }
        }
    }
    for(int i=1;i<=q;i++)
    {
        int t,l,r;
        cin>>t>>l>>r;
        E1.pb({l,-i,t,0,0});
        E1.pb({r,i,t,0,0});
        E2.pb({l-t,-i,t,0,0});
        E2.pb({r-t,i,t,0,0});
    }
    sort(all(E1),cmp);
    for(auto x:E1)
    {
        if(x.b<0) ans[-x.b]-=que(x.l);
        if(x.b>0) ans[x.b]+=que(x.l);
        if(x.b==0)
        {
            ins(x.r,x.x);
            ins(x.l-1,-x.x);
        }
    }
    memset(BIT,0,sizeof BIT);
    sort(all(E2),cmp);
    for(auto x:E2)
    {
        if(x.b<0) ans[-x.b]-=que(x.l);
        if(x.b>0) ans[x.b]+=que(x.l);
        if(x.b==0)
        {
            ins(x.r,x.x);
            ins(x.l-1,-x.x);
        }
    }
    for(int i=1;i<=q;i++) cout<<ans[i]<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 2 ms 1856 KB Output is correct
9 Correct 2 ms 1864 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1864 KB Output is correct
16 Correct 1 ms 1864 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1864 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 2 ms 1872 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 1860 KB Output is correct
29 Correct 2 ms 1864 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Runtime error 336 ms 90520 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Runtime error 400 ms 108440 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 229 ms 60424 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 2 ms 1856 KB Output is correct
9 Correct 2 ms 1864 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1864 KB Output is correct
16 Correct 1 ms 1864 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1864 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 2 ms 1872 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 1860 KB Output is correct
29 Correct 2 ms 1864 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Runtime error 336 ms 90520 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -