Submission #1280772

#TimeUsernameProblemLanguageResultExecution timeMemory
1280772quangminh412Growing Trees (BOI11_grow)C++17
100 / 100
84 ms2344 KiB
/* Ben Watson Handle codeforces : quangminh98 Current Theme: Transformers !!!! */ #include <bits/stdc++.h> using namespace std; #define ll long long const string name = "test"; void solve(); signed main() { if (fopen((name + ".inp").c_str(), "r")) { freopen((name + ".inp").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } // main program const int maxn = 1e5 + 1; struct FenwickTree { vector<int> bits; int n; FenwickTree(int n) : n(n) { bits.resize(n + 1, 0); } void update(int pos, int val) { for (; pos <= n; pos += (pos & (-pos))) bits[pos] += val; } void update(int l, int r, int val) { if (l > r) return; if (r + 1 <= n) update(r + 1, -val); update(l, val); } int query(int pos) { int res = 0; for (; pos > 0; pos -= (pos & (-pos))) res += bits[pos]; return res; } }; int n, m; int a[maxn]; FenwickTree bit(maxn); int Greater(int x) // first position i such as a[i] >= x { int l = 1, r = n; int res = n + 1; while (l <= r) { int mid = l + r >> 1; if (bit.query(mid) >= x) { res = mid; r = mid - 1; } else l = mid + 1; } return res; } int Less(int x) // last position i such as a[i] <= x { int l = 1, r = n; int res = 0; while (l <= r) { int mid = l + r >> 1; if (bit.query(mid) <= x) { res = mid; l = mid + 1; } else r = mid - 1; } return res; } void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) bit.update(i, i, a[i]); while (m--) { char type; cin >> type; if (type == 'F') { int c, h; cin >> c >> h; int st = Greater(h); if (st == n + 1) continue; c = min(c, n - st + 1); int val = bit.query(st + c - 1); int R = Less(val), L = Greater(val), cnt = st + c - L; bit.update(st, L - 1, 1); bit.update(R - cnt + 1, R, 1); } else { int l, r; cin >> l >> r; int L = Greater(l), R = Less(r); cout << max(0, R - L + 1) << '\n'; } } }

Compilation message (stderr)

grow.cpp: In function 'int main()':
grow.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((name + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...