Submission #413596

#TimeUsernameProblemLanguageResultExecution timeMemory
413596cpp219Fortune Telling 2 (JOI14_fortune_telling2)C++14
100 / 100
329 ms21464 KiB
#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 + 9; const ll Log2 = 20; const ll inf = 1e16 + 7; typedef pair<ll,ll> LL; struct data{ ll x,y,id,dummy; }; data a[N]; ll n,k,st[4*N],q[N]; bool lf(data a,data b){ return max(a.x,a.y) > max(b.x,b.y); } void upd(ll id,ll l,ll r,ll u,ll val){ if (u < l||r < u) return; if (l == r){ st[id] = val; return; } ll mid = (l + r)/2; upd(id*2,l,mid,u,val); upd(id*2 + 1,mid + 1,r,u,val); st[id] = max(st[id*2],st[id*2 + 1]); } /// last but >= val ll WalkLast(ll id,ll l,ll r,ll val){ if (l == r){ if (st[id] >= val) return l; return 0; } ll mid = (l + r)/2; if (st[id*2 + 1] >= val) return WalkLast(id*2 + 1,mid + 1,r,val); return WalkLast(id*2,l,mid,val); } ll WalkFirst(ll id,ll l,ll r,ll val){ if (l == r){ if (st[id] >= val) return l; return inf; } ll mid = (l + r)/2; if (st[id*2] >= val) return WalkFirst(id*2,l,mid,val); return WalkFirst(id*2 + 1,mid + 1,r,val); } ll bit[N]; void updBIT(ll p,ll val){ for (ll i = p;i <= k;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; } vector<ll> pos; bool cmp(ll x,ll y){ return q[x] > q[y]; } 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>>k; for (ll i = 1;i <= n;i++){ cin>>a[i].x>>a[i].y,a[i].id = i; if (a[i].x < a[i].y) a[i].dummy = 1,swap(a[i].x,a[i].y); } for (ll i = 1;i <= k;i++) cin>>q[i],upd(1,1,k,i,q[i]),pos.push_back(i); sort(a + 1,a + n + 1,lf); sort(pos.begin(),pos.end(),cmp); ll cur = 0,kq = 0,mn = inf; for (ll i = 1;i <= n;i++){ while(cur < k&&q[pos[cur]] >= a[i].x){ mn = min(mn,pos[cur]); upd(1,1,k,pos[cur],-inf); updBIT(pos[cur],1); cur++; } ll nxt = WalkLast(1,1,k,a[i].y),prv = WalkFirst(1,1,k,a[i].y); ll ans = Get(k) - Get(nxt); ans %= 2; if (!nxt) ans += a[i].dummy; ans %= 2; if (ans) kq += a[i].y;//cout<<a[i].y<<"\n"; else kq += a[i].x;//cout<<a[i].x<<"\n"; } cout<<kq; }

Compilation message (stderr)

fortune_telling2.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
fortune_telling2.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:99:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   99 |         if (!nxt) ans += a[i].dummy; ans %= 2;
      |         ^~
fortune_telling2.cpp:99:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   99 |         if (!nxt) ans += a[i].dummy; ans %= 2;
      |                                      ^~~
fortune_telling2.cpp:97:41: warning: unused variable 'prv' [-Wunused-variable]
   97 |         ll nxt = WalkLast(1,1,k,a[i].y),prv = WalkFirst(1,1,k,a[i].y);
      |                                         ^~~
fortune_telling2.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...