Submission #885459

#TimeUsernameProblemLanguageResultExecution timeMemory
885459codexistentSails (IOI07_sails)C++14
0 / 100
45 ms1984 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define RFOR(i, a, b) for(int i = a; i >= b; i--) #define ll long long struct RangeFenwick { vector<int> bit[2]; int size; RangeFenwick(int n){ size = n + 1; bit[0].assign(size + 1, 0), bit[1].assign(size + 1, 0); } void add(bool t, int i, int x){ for(; i < size; i += i & -i) bit[t][i] += x; } void range_add(int l, int r, int x){ add(0, l, x), add(0, r + 1, -x); add(1, l, x * (l - 1)), add(1, r + 1, -x * r); } int pfx_helper(int t, int i){ int r = 0; for(; i > 0; i -= i & -i) r += bit[t][i]; return r; } int pfx(int i){ return pfx_helper(0, i)*i - pfx_helper(1, i); } int pt(int i){ return pfx(i) - pfx(i - 1); } }; int main(){ int N; cin >> N; pair<int, int> M[N]; FOR(i, 0, N - 1){ int h, s; cin >> h >> s; M[i] = make_pair(h, s); } sort(M, M + N); RangeFenwick T(N); FOR(i, 0, N - 1){ int H = M[i].first, S = M[i].second; int PM = T.pt(H - S + 1); // prev max sail /*int a = 1, b = H; // a = lowest index with value <= PM while(a < b){ int m = (a + b) / 2; if(PM >= T.pt(m)){ b = m; }else{ a = m + 1; } } int a2 = 1, b2 = H; // a2 = highest index w value <= PM while(a2 < b2){ int m = (a2 + b2 + 1) / 2; if(PM <= T.pt(m)){ a2 = m; }else{ b2 = m - 1; } cout << "HERE" << endl; }*/ break; //if(a2 != H) T.range_add(a2 + 1, H, 1); //T.range_add(a, a2 - (H - S + 1 - a), 1); } /*ll R = 0, r = 0, p = -1; RFOR(i, N, 1) if(T.pt(i) != 0) { if(T.pt(i) - 1 != p) { r += T.pt(i) - 1; p = T.pt(i) - 1; } R += r; } cout << R << endl;*/ }

Compilation message (stderr)

sails.cpp: In function 'int main()':
sails.cpp:55:13: warning: unused variable 'PM' [-Wunused-variable]
   55 |         int PM = T.pt(H - S + 1); // prev max sail
      |             ^~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...