답안 #447678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447678 2021-07-27T10:26:37 Z cpp219 Snowball (JOI21_ho_t2) C++14
100 / 100
158 ms 17456 KB
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2e5 + 9;
const ll Log2 = 21;
const ll inf = 1e18 + 7;

ll n,Q,a[N],x,L,R,q[N];

vector<ll> ve,vw;
vector<LL> Toe,Tow; /// fs = desired value

int main(){
    ios_base::sync_with_stdio(NULL); 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>>a[i];
    ll now = 0;
    for (ll i = 1;i <= Q;i++){
        cin>>x; q[i] = q[i - 1] + x;
    }
    //cout<<q[0]; return 0;
    for (ll i = 1;i <= Q;i++){
        L = max(L,-q[i]); R = max(R,q[i]); //cout<<q[1]; return 0;
        if (Toe.empty() || Toe.back().fs < R) Toe.push_back({R,L}),ve.push_back(R + L);
        if (Tow.empty() || Tow.back().fs < L) Tow.push_back({L,R}),vw.push_back(L + R);
    }
    //for (auto i : Tow) cout<<i.fs<<" "<<i.sc<<"\n"; return 0;
    a[0] = -inf; a[n + 1] = inf;
    for (ll i = 1;i <= n;i++){
        ll it1 = upper_bound(ve.begin(),ve.end(),a[i + 1] - a[i]) - ve.begin();
        ll it2 = upper_bound(vw.begin(),vw.end(),a[i] - a[i - 1]) - vw.begin();
        ll ans = 0;
        if (it1 < ve.size()){
            ll kq = a[i + 1] - a[i] - Toe[it1].sc;
            if (it1) kq = max(kq,Toe[it1 - 1].fs); ans += max(0ll,kq);
        }
        else ans += Toe.back().fs;
        if (it2 < vw.size()){
            ll kq = a[i] - a[i - 1] - Tow[it2].sc;
            if (it2) kq = max(kq,Tow[it2 - 1].fs); ans += max(0ll,kq);
        }
        else ans += Tow.back().fs;

        cout<<ans<<"\n";
    }
}

Compilation message

Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
Main.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
Main.cpp: In function 'int main()':
Main.cpp:46:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (it1 < ve.size()){
      |             ~~~~^~~~~~~~~~~
Main.cpp:48:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   48 |             if (it1) kq = max(kq,Toe[it1 - 1].fs); ans += max(0ll,kq);
      |             ^~
Main.cpp:48:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   48 |             if (it1) kq = max(kq,Toe[it1 - 1].fs); ans += max(0ll,kq);
      |                                                    ^~~
Main.cpp:51:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         if (it2 < vw.size()){
      |             ~~~~^~~~~~~~~~~
Main.cpp:53:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   53 |             if (it2) kq = max(kq,Tow[it2 - 1].fs); ans += max(0ll,kq);
      |             ^~
Main.cpp:53:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   53 |             if (it2) kq = max(kq,Tow[it2 - 1].fs); ans += max(0ll,kq);
      |                                                    ^~~
Main.cpp:30:8: warning: unused variable 'now' [-Wunused-variable]
   30 |     ll now = 0;
      |        ^~~
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(task".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 40 ms 10240 KB Output is correct
21 Correct 37 ms 9772 KB Output is correct
22 Correct 38 ms 9220 KB Output is correct
23 Correct 34 ms 9044 KB Output is correct
24 Correct 47 ms 9808 KB Output is correct
25 Correct 157 ms 14400 KB Output is correct
26 Correct 158 ms 15012 KB Output is correct
27 Correct 150 ms 14060 KB Output is correct
28 Correct 148 ms 13728 KB Output is correct
29 Correct 137 ms 10800 KB Output is correct
30 Correct 94 ms 7364 KB Output is correct
31 Correct 71 ms 6808 KB Output is correct
32 Correct 67 ms 6884 KB Output is correct
33 Correct 13 ms 1740 KB Output is correct
34 Correct 114 ms 9300 KB Output is correct
35 Correct 121 ms 9112 KB Output is correct
36 Correct 149 ms 14488 KB Output is correct
37 Correct 149 ms 12944 KB Output is correct
38 Correct 146 ms 14112 KB Output is correct
39 Correct 142 ms 13872 KB Output is correct
40 Correct 105 ms 13888 KB Output is correct
41 Correct 40 ms 11288 KB Output is correct
42 Correct 65 ms 6920 KB Output is correct
43 Correct 101 ms 15904 KB Output is correct
44 Correct 41 ms 10148 KB Output is correct
45 Correct 91 ms 13736 KB Output is correct
46 Correct 100 ms 15996 KB Output is correct
47 Correct 96 ms 13240 KB Output is correct
48 Correct 113 ms 17456 KB Output is correct