Submission #765284

#TimeUsernameProblemLanguageResultExecution timeMemory
765284CookiePilot (NOI19_pilot)C++14
100 / 100
431 ms63752 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("VNOICUP.INP"); ofstream fout("VNOICUP.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; const ll mod = 1e9 + 7; const int mxn = 1e6, mxm = 1e5; int n, q; int h[mxn + 1], y[mxn + 1], l[mxn + 1], r[mxn + 1], ok[mxn + 1]; ll a[mxn + 1], res[mxn + 1]; set<int>bad; ll ans = 0; ll sm(ll x){ return(x * (x + 1) / 2); } void add(int id){ if(ok[id - 1] && ok[id + 1]){ r[id] = r[id + 1]; l[id] = l[id - 1]; l[r[id + 1]] = l[id - 1]; r[l[id - 1]] = r[id + 1]; ans -= sm(id - 1 - l[id - 1] + 1); ans -= sm(r[id + 1] - id); ans += sm(r[id + 1] - l[id - 1] + 1); }else if(ok[id - 1]){ l[id] = l[id - 1]; r[l[id - 1]] = id; ans -= sm(id - 1 - l[id - 1] + 1); ans += sm(id - l[id - 1] + 1); }else if(ok[id + 1]){ r[id] = r[id + 1]; l[r[id + 1]] = id; ans -= sm(r[id + 1] - id); ans += sm(r[id + 1] - id + 1); }else{ ans++; } ok[id] = 1; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; vt<pii>comp; for(int i = 1; i <= n; i++){ cin >> a[i]; comp.pb(make_pair(a[i], i)); } for(int i = 1; i <= n; i++){ l[i] = r[i] = i; ok[i] = 0; } vt<pii>queries; forr(i, 0, q){ int y; cin >> y; queries.pb({y, i}); } sort(queries.begin(), queries.end()); sort(comp.begin(), comp.end()); int R = 0; for(auto [y, id]: queries){ while(R < sz(comp) && comp[R].fi <= y){ add(comp[R].se); R++; } res[id] = ans; } forr(i, 0, q){ cout << res[i] << "\n"; } return(0); }

Compilation message (stderr)

pilot.cpp: In function 'int main()':
pilot.cpp:64:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |     for(auto [y, id]: queries){
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...