Submission #447678

#TimeUsernameProblemLanguageResultExecution timeMemory
447678cpp219Snowball (JOI21_ho_t2)C++14
100 / 100
158 ms17456 KiB
#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 (stderr)

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...