답안 #908454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908454 2024-01-16T12:26:17 Z bachhoangxuan Fire (JOI20_ho_t5) C++17
100 / 100
363 ms 56216 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/

#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=131;

int n,q,a[maxn],res[maxn],s[maxn];
vector<pii> qq[maxn];

int sz[maxn],k[maxn],d[maxn];

struct BIT{
    int bit[2*maxn];
    void update(int x,int val){
        assert(x);
        for(int i=x;i<=2*n;i+=(i&(-i))) bit[i]+=val;
    }
    int query(int x){
        int res=0;
        for(int i=x;i>=1;i-=(i&(-i))) res+=bit[i];
        return res;
    }
};

struct DS{
    BIT f0,f1,g0,g1;
    void update(int D,int K,int S,int val){
        f0.update(S+K+n,D*val);
        f1.update(S+K+n,D*(S+K)*val);
        g0.update(K,D*val);
        g1.update(K,D*K*val);
    }
    int query(int T,int T0){
        int res=0;
        res+=f1.query(T+n);
        res+=T*(f0.query(2*n)-f0.query(T+n));
        res-=g1.query(T0);
        res-=(g0.query(2*n)-g0.query(T0))*T;
        return res;
    }
}d0,d1;

void solve(){
    cin >> n >> q;
    for(int i=1;i<=n;i++) cin >> a[i],s[i]=s[i-1]+a[i];
    for(int i=1;i<=q;i++){
        int t,l,r;cin >> t >> l >> r;
        t=min(t,n-1);
        qq[l-1].push_back({-i,t});
        qq[r].push_back({i,t});
        res[i]=s[r]-s[l-1];
    }
    vector<int> v;
    for(int i=1;i<=n;i++){
        while(!v.empty() && a[v.back()]<a[i]){
            int x=v.back();v.pop_back();
            if(v.empty()) break;
            d0.update(d[x],k[x],sz[x],-1);
            sz[x]+=i-1;
            d1.update(d[x],k[x],sz[x],1);
        }
        if(!v.empty()){
            d[i]=a[v.back()]-a[i];
            k[i]=i-v.back();
            sz[i]=1-i;
            d0.update(d[i],k[i],sz[i],1);
            //cout << d[i] << ' ' << k[i] << ' ' << sz[i] << ' ' << i << '\n';
        }
        v.push_back(i);
        for(auto [id,T]:qq[i]){
            int val=d1.query(T+1,T+1)+d0.query(T+1-i,T+1);
            val+=i*d0.g0.query(T+1);
            if(id<0) res[-id]-=val;
            else res[id]+=val;
        }
    }
    for(int i=1;i<=q;i++) cout << res[i] << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 3 ms 14680 KB Output is correct
4 Correct 5 ms 22872 KB Output is correct
5 Correct 4 ms 14680 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 3 ms 14796 KB Output is correct
8 Correct 5 ms 22872 KB Output is correct
9 Correct 4 ms 14684 KB Output is correct
10 Correct 5 ms 14680 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 7 ms 29020 KB Output is correct
14 Correct 5 ms 22872 KB Output is correct
15 Correct 5 ms 22876 KB Output is correct
16 Correct 4 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 4 ms 14680 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 5 ms 22876 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14680 KB Output is correct
24 Correct 4 ms 14684 KB Output is correct
25 Correct 4 ms 14684 KB Output is correct
26 Correct 3 ms 14684 KB Output is correct
27 Correct 3 ms 14684 KB Output is correct
28 Correct 3 ms 14684 KB Output is correct
29 Correct 3 ms 14684 KB Output is correct
30 Correct 3 ms 14880 KB Output is correct
31 Correct 4 ms 14680 KB Output is correct
32 Correct 3 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 239 ms 40256 KB Output is correct
3 Correct 225 ms 38224 KB Output is correct
4 Correct 223 ms 41932 KB Output is correct
5 Correct 233 ms 40136 KB Output is correct
6 Correct 233 ms 41296 KB Output is correct
7 Correct 245 ms 42836 KB Output is correct
8 Correct 240 ms 48464 KB Output is correct
9 Correct 239 ms 42684 KB Output is correct
10 Correct 237 ms 40164 KB Output is correct
11 Correct 225 ms 38484 KB Output is correct
12 Correct 238 ms 38300 KB Output is correct
13 Correct 229 ms 41728 KB Output is correct
14 Correct 235 ms 41948 KB Output is correct
15 Correct 211 ms 42396 KB Output is correct
16 Correct 243 ms 55632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 279 ms 41296 KB Output is correct
3 Correct 240 ms 36648 KB Output is correct
4 Correct 253 ms 38040 KB Output is correct
5 Correct 259 ms 37180 KB Output is correct
6 Correct 267 ms 38772 KB Output is correct
7 Correct 264 ms 37328 KB Output is correct
8 Correct 277 ms 37724 KB Output is correct
9 Correct 256 ms 37200 KB Output is correct
10 Correct 247 ms 37200 KB Output is correct
11 Correct 247 ms 37456 KB Output is correct
12 Correct 227 ms 36624 KB Output is correct
13 Correct 306 ms 39508 KB Output is correct
14 Correct 248 ms 37200 KB Output is correct
15 Correct 271 ms 41040 KB Output is correct
16 Correct 235 ms 36944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 38708 KB Output is correct
2 Correct 225 ms 38080 KB Output is correct
3 Correct 252 ms 46036 KB Output is correct
4 Correct 238 ms 38608 KB Output is correct
5 Correct 250 ms 36340 KB Output is correct
6 Correct 224 ms 36036 KB Output is correct
7 Correct 221 ms 34756 KB Output is correct
8 Correct 252 ms 43456 KB Output is correct
9 Correct 244 ms 34316 KB Output is correct
10 Correct 302 ms 45252 KB Output is correct
11 Correct 228 ms 36492 KB Output is correct
12 Correct 280 ms 43708 KB Output is correct
13 Correct 244 ms 45668 KB Output is correct
14 Correct 254 ms 45512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 3 ms 14680 KB Output is correct
4 Correct 5 ms 22872 KB Output is correct
5 Correct 4 ms 14680 KB Output is correct
6 Correct 4 ms 14684 KB Output is correct
7 Correct 3 ms 14796 KB Output is correct
8 Correct 5 ms 22872 KB Output is correct
9 Correct 4 ms 14684 KB Output is correct
10 Correct 5 ms 14680 KB Output is correct
11 Correct 3 ms 14680 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 7 ms 29020 KB Output is correct
14 Correct 5 ms 22872 KB Output is correct
15 Correct 5 ms 22876 KB Output is correct
16 Correct 4 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 4 ms 14680 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 5 ms 22876 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14680 KB Output is correct
24 Correct 4 ms 14684 KB Output is correct
25 Correct 4 ms 14684 KB Output is correct
26 Correct 3 ms 14684 KB Output is correct
27 Correct 3 ms 14684 KB Output is correct
28 Correct 3 ms 14684 KB Output is correct
29 Correct 3 ms 14684 KB Output is correct
30 Correct 3 ms 14880 KB Output is correct
31 Correct 4 ms 14680 KB Output is correct
32 Correct 3 ms 14684 KB Output is correct
33 Correct 239 ms 40256 KB Output is correct
34 Correct 225 ms 38224 KB Output is correct
35 Correct 223 ms 41932 KB Output is correct
36 Correct 233 ms 40136 KB Output is correct
37 Correct 233 ms 41296 KB Output is correct
38 Correct 245 ms 42836 KB Output is correct
39 Correct 240 ms 48464 KB Output is correct
40 Correct 239 ms 42684 KB Output is correct
41 Correct 237 ms 40164 KB Output is correct
42 Correct 225 ms 38484 KB Output is correct
43 Correct 238 ms 38300 KB Output is correct
44 Correct 229 ms 41728 KB Output is correct
45 Correct 235 ms 41948 KB Output is correct
46 Correct 211 ms 42396 KB Output is correct
47 Correct 243 ms 55632 KB Output is correct
48 Correct 279 ms 41296 KB Output is correct
49 Correct 240 ms 36648 KB Output is correct
50 Correct 253 ms 38040 KB Output is correct
51 Correct 259 ms 37180 KB Output is correct
52 Correct 267 ms 38772 KB Output is correct
53 Correct 264 ms 37328 KB Output is correct
54 Correct 277 ms 37724 KB Output is correct
55 Correct 256 ms 37200 KB Output is correct
56 Correct 247 ms 37200 KB Output is correct
57 Correct 247 ms 37456 KB Output is correct
58 Correct 227 ms 36624 KB Output is correct
59 Correct 306 ms 39508 KB Output is correct
60 Correct 248 ms 37200 KB Output is correct
61 Correct 271 ms 41040 KB Output is correct
62 Correct 235 ms 36944 KB Output is correct
63 Correct 249 ms 38708 KB Output is correct
64 Correct 225 ms 38080 KB Output is correct
65 Correct 252 ms 46036 KB Output is correct
66 Correct 238 ms 38608 KB Output is correct
67 Correct 250 ms 36340 KB Output is correct
68 Correct 224 ms 36036 KB Output is correct
69 Correct 221 ms 34756 KB Output is correct
70 Correct 252 ms 43456 KB Output is correct
71 Correct 244 ms 34316 KB Output is correct
72 Correct 302 ms 45252 KB Output is correct
73 Correct 228 ms 36492 KB Output is correct
74 Correct 280 ms 43708 KB Output is correct
75 Correct 244 ms 45668 KB Output is correct
76 Correct 254 ms 45512 KB Output is correct
77 Correct 240 ms 37956 KB Output is correct
78 Correct 260 ms 40020 KB Output is correct
79 Correct 245 ms 39760 KB Output is correct
80 Correct 247 ms 38480 KB Output is correct
81 Correct 363 ms 55700 KB Output is correct
82 Correct 264 ms 37708 KB Output is correct
83 Correct 263 ms 41716 KB Output is correct
84 Correct 329 ms 38524 KB Output is correct
85 Correct 263 ms 41596 KB Output is correct
86 Correct 326 ms 46616 KB Output is correct
87 Correct 288 ms 38480 KB Output is correct
88 Correct 289 ms 38284 KB Output is correct
89 Correct 300 ms 38476 KB Output is correct
90 Correct 299 ms 38324 KB Output is correct
91 Correct 230 ms 38120 KB Output is correct
92 Correct 309 ms 37684 KB Output is correct
93 Correct 307 ms 38232 KB Output is correct
94 Correct 295 ms 56216 KB Output is correct
95 Correct 247 ms 38404 KB Output is correct
96 Correct 261 ms 38420 KB Output is correct
97 Correct 255 ms 38684 KB Output is correct
98 Correct 247 ms 41388 KB Output is correct
99 Correct 258 ms 41304 KB Output is correct
100 Correct 296 ms 55636 KB Output is correct
101 Correct 226 ms 41356 KB Output is correct
102 Correct 249 ms 41976 KB Output is correct