답안 #403466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403466 2021-05-13T08:04:45 Z cpp219 Fire (JOI20_ho_t5) C++14
100 / 100
415 ms 92424 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 16;
const ll Log2 = 19;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
///Road to EF/M

ll s[N],n,Q,T,l,r,ans[N],pre[N],suf[N];

struct Query{
    ll l,r,id;
};
vector<Query> q[N];
vector<LL> f[N],g[N];
ll bit[N];

void upd(ll p,ll val){
    for (ll i = p;i < N;i += i & -i) bit[i] += val;
}

ll Get(ll p){
    ll res = 0;
    for (ll i = p;i > 0;i -= i & -i) res += bit[i];
    return res;
}
stack<ll> st;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>Q;
    for (ll i = 1;i <= n;i++) cin>>s[i];
    for (ll i = 1;i <= Q;i++){
        cin>>T>>l>>r;
        q[T].push_back({l,r,i});
    }
    for (ll i = 1;i <= n;i++){
        while(!st.empty() && s[st.top()] <= s[i]) st.pop();
        if (!st.empty()) pre[i] = st.top();
        st.push(i);
    }
    while(!st.empty()) st.pop();
    for (ll i = n;i > 0;i--){
        while(!st.empty() && s[st.top()] < s[i]) st.pop();
        if (!st.empty()) suf[i] = st.top();
        else suf[i] = n + 1;
        st.push(i);
    }
    for (ll i = 1;i <= n;i++){
        if (!pre[i] || i - pre[i] > suf[i] - i){
            for (ll j = i;j < suf[i];j++){
                f[j - i].push_back({j,s[i]});
                if (pre[i]) f[j - pre[i]].push_back({j,-s[i]});
            }
        }
        else{
            for (ll j = i;j > pre[i];j--){
                g[i - j].push_back({j,s[i]});
                g[suf[i] - j].push_back({j,-s[i]});
            }
        }
    }
    for (ll i = 0;i <= n;i++){
        for (auto j : f[i]) upd(j.fs,j.sc);
        for (auto j : q[i]) ans[j.id] += Get(j.r) - Get(j.l - 1);
    }
    memset(bit,0,sizeof(bit));
    for (ll i = 0;i <= n;i++){
        for (auto j : g[i]) upd(j.fs,j.sc);
        for (auto j : q[i]) ans[j.id] += Get(j.r - i) - Get(j.l - i - 1);
    }
    for (ll i = 1;i <= Q;i++) cout<<ans[i]<<"\n";
}

Compilation message

ho_t5.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
ho_t5.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15948 KB Output is correct
2 Correct 10 ms 15944 KB Output is correct
3 Correct 10 ms 15960 KB Output is correct
4 Correct 10 ms 15948 KB Output is correct
5 Correct 10 ms 15948 KB Output is correct
6 Correct 11 ms 15948 KB Output is correct
7 Correct 10 ms 15948 KB Output is correct
8 Correct 10 ms 15948 KB Output is correct
9 Correct 10 ms 15956 KB Output is correct
10 Correct 12 ms 15948 KB Output is correct
11 Correct 10 ms 15956 KB Output is correct
12 Correct 10 ms 15956 KB Output is correct
13 Correct 10 ms 15948 KB Output is correct
14 Correct 10 ms 15960 KB Output is correct
15 Correct 10 ms 15948 KB Output is correct
16 Correct 11 ms 15964 KB Output is correct
17 Correct 10 ms 15948 KB Output is correct
18 Correct 10 ms 15960 KB Output is correct
19 Correct 12 ms 15948 KB Output is correct
20 Correct 10 ms 15964 KB Output is correct
21 Correct 10 ms 15960 KB Output is correct
22 Correct 10 ms 15948 KB Output is correct
23 Correct 10 ms 16028 KB Output is correct
24 Correct 10 ms 15948 KB Output is correct
25 Correct 10 ms 15984 KB Output is correct
26 Correct 11 ms 16060 KB Output is correct
27 Correct 10 ms 15948 KB Output is correct
28 Correct 10 ms 15948 KB Output is correct
29 Correct 13 ms 15964 KB Output is correct
30 Correct 13 ms 15956 KB Output is correct
31 Correct 11 ms 15948 KB Output is correct
32 Correct 11 ms 15948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15948 KB Output is correct
2 Correct 291 ms 79508 KB Output is correct
3 Correct 317 ms 85264 KB Output is correct
4 Correct 290 ms 81736 KB Output is correct
5 Correct 342 ms 89484 KB Output is correct
6 Correct 296 ms 87340 KB Output is correct
7 Correct 287 ms 85120 KB Output is correct
8 Correct 294 ms 87252 KB Output is correct
9 Correct 317 ms 87872 KB Output is correct
10 Correct 282 ms 84636 KB Output is correct
11 Correct 292 ms 86056 KB Output is correct
12 Correct 290 ms 86700 KB Output is correct
13 Correct 295 ms 85352 KB Output is correct
14 Correct 296 ms 86728 KB Output is correct
15 Correct 301 ms 86956 KB Output is correct
16 Correct 315 ms 91584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15948 KB Output is correct
2 Correct 395 ms 83572 KB Output is correct
3 Correct 351 ms 87352 KB Output is correct
4 Correct 415 ms 92424 KB Output is correct
5 Correct 391 ms 83092 KB Output is correct
6 Correct 375 ms 85448 KB Output is correct
7 Correct 361 ms 85272 KB Output is correct
8 Correct 349 ms 85296 KB Output is correct
9 Correct 348 ms 84140 KB Output is correct
10 Correct 375 ms 87528 KB Output is correct
11 Correct 371 ms 89840 KB Output is correct
12 Correct 371 ms 88400 KB Output is correct
13 Correct 382 ms 89208 KB Output is correct
14 Correct 335 ms 82044 KB Output is correct
15 Correct 360 ms 87732 KB Output is correct
16 Correct 386 ms 88608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 38976 KB Output is correct
2 Correct 219 ms 39476 KB Output is correct
3 Correct 205 ms 39920 KB Output is correct
4 Correct 209 ms 39324 KB Output is correct
5 Correct 206 ms 39904 KB Output is correct
6 Correct 208 ms 39036 KB Output is correct
7 Correct 204 ms 39580 KB Output is correct
8 Correct 209 ms 39712 KB Output is correct
9 Correct 200 ms 39628 KB Output is correct
10 Correct 198 ms 39332 KB Output is correct
11 Correct 229 ms 39588 KB Output is correct
12 Correct 206 ms 39324 KB Output is correct
13 Correct 254 ms 39116 KB Output is correct
14 Correct 208 ms 39324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15948 KB Output is correct
2 Correct 10 ms 15944 KB Output is correct
3 Correct 10 ms 15960 KB Output is correct
4 Correct 10 ms 15948 KB Output is correct
5 Correct 10 ms 15948 KB Output is correct
6 Correct 11 ms 15948 KB Output is correct
7 Correct 10 ms 15948 KB Output is correct
8 Correct 10 ms 15948 KB Output is correct
9 Correct 10 ms 15956 KB Output is correct
10 Correct 12 ms 15948 KB Output is correct
11 Correct 10 ms 15956 KB Output is correct
12 Correct 10 ms 15956 KB Output is correct
13 Correct 10 ms 15948 KB Output is correct
14 Correct 10 ms 15960 KB Output is correct
15 Correct 10 ms 15948 KB Output is correct
16 Correct 11 ms 15964 KB Output is correct
17 Correct 10 ms 15948 KB Output is correct
18 Correct 10 ms 15960 KB Output is correct
19 Correct 12 ms 15948 KB Output is correct
20 Correct 10 ms 15964 KB Output is correct
21 Correct 10 ms 15960 KB Output is correct
22 Correct 10 ms 15948 KB Output is correct
23 Correct 10 ms 16028 KB Output is correct
24 Correct 10 ms 15948 KB Output is correct
25 Correct 10 ms 15984 KB Output is correct
26 Correct 11 ms 16060 KB Output is correct
27 Correct 10 ms 15948 KB Output is correct
28 Correct 10 ms 15948 KB Output is correct
29 Correct 13 ms 15964 KB Output is correct
30 Correct 13 ms 15956 KB Output is correct
31 Correct 11 ms 15948 KB Output is correct
32 Correct 11 ms 15948 KB Output is correct
33 Correct 291 ms 79508 KB Output is correct
34 Correct 317 ms 85264 KB Output is correct
35 Correct 290 ms 81736 KB Output is correct
36 Correct 342 ms 89484 KB Output is correct
37 Correct 296 ms 87340 KB Output is correct
38 Correct 287 ms 85120 KB Output is correct
39 Correct 294 ms 87252 KB Output is correct
40 Correct 317 ms 87872 KB Output is correct
41 Correct 282 ms 84636 KB Output is correct
42 Correct 292 ms 86056 KB Output is correct
43 Correct 290 ms 86700 KB Output is correct
44 Correct 295 ms 85352 KB Output is correct
45 Correct 296 ms 86728 KB Output is correct
46 Correct 301 ms 86956 KB Output is correct
47 Correct 315 ms 91584 KB Output is correct
48 Correct 395 ms 83572 KB Output is correct
49 Correct 351 ms 87352 KB Output is correct
50 Correct 415 ms 92424 KB Output is correct
51 Correct 391 ms 83092 KB Output is correct
52 Correct 375 ms 85448 KB Output is correct
53 Correct 361 ms 85272 KB Output is correct
54 Correct 349 ms 85296 KB Output is correct
55 Correct 348 ms 84140 KB Output is correct
56 Correct 375 ms 87528 KB Output is correct
57 Correct 371 ms 89840 KB Output is correct
58 Correct 371 ms 88400 KB Output is correct
59 Correct 382 ms 89208 KB Output is correct
60 Correct 335 ms 82044 KB Output is correct
61 Correct 360 ms 87732 KB Output is correct
62 Correct 386 ms 88608 KB Output is correct
63 Correct 211 ms 38976 KB Output is correct
64 Correct 219 ms 39476 KB Output is correct
65 Correct 205 ms 39920 KB Output is correct
66 Correct 209 ms 39324 KB Output is correct
67 Correct 206 ms 39904 KB Output is correct
68 Correct 208 ms 39036 KB Output is correct
69 Correct 204 ms 39580 KB Output is correct
70 Correct 209 ms 39712 KB Output is correct
71 Correct 200 ms 39628 KB Output is correct
72 Correct 198 ms 39332 KB Output is correct
73 Correct 229 ms 39588 KB Output is correct
74 Correct 206 ms 39324 KB Output is correct
75 Correct 254 ms 39116 KB Output is correct
76 Correct 208 ms 39324 KB Output is correct
77 Correct 365 ms 86992 KB Output is correct
78 Correct 358 ms 89588 KB Output is correct
79 Correct 367 ms 88548 KB Output is correct
80 Correct 370 ms 87764 KB Output is correct
81 Correct 353 ms 87684 KB Output is correct
82 Correct 370 ms 87968 KB Output is correct
83 Correct 356 ms 86244 KB Output is correct
84 Correct 348 ms 83596 KB Output is correct
85 Correct 375 ms 86596 KB Output is correct
86 Correct 379 ms 92236 KB Output is correct
87 Correct 325 ms 89116 KB Output is correct
88 Correct 310 ms 83348 KB Output is correct
89 Correct 313 ms 82332 KB Output is correct
90 Correct 315 ms 87544 KB Output is correct
91 Correct 332 ms 87780 KB Output is correct
92 Correct 324 ms 88808 KB Output is correct
93 Correct 326 ms 89204 KB Output is correct
94 Correct 329 ms 87708 KB Output is correct
95 Correct 335 ms 88088 KB Output is correct
96 Correct 342 ms 90860 KB Output is correct
97 Correct 335 ms 88464 KB Output is correct
98 Correct 343 ms 86396 KB Output is correct
99 Correct 361 ms 88064 KB Output is correct
100 Correct 363 ms 90036 KB Output is correct
101 Correct 405 ms 85552 KB Output is correct
102 Correct 347 ms 85364 KB Output is correct