답안 #447671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447671 2021-07-27T09:56:31 Z cpp219 Snowball (JOI21_ho_t2) C++14
0 / 100
2 ms 460 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 "tst"
    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 : Toe) 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 += 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 += 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 += 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 += 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 += 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 += 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 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 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 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 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Halted 0 ms 0 KB -