Submission #881787

#TimeUsernameProblemLanguageResultExecution timeMemory
881787cpptowinGrowing Trees (BOI11_grow)C++17
0 / 100
106 ms11140 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define int long long #define inf 1000000000 #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1 << j)) #define onbit(i, j) (i | (1 << j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; int n, q; int a[maxn]; int st[maxn], lazy[maxn]; void down(int id) { st[id << 1] += lazy[id]; st[id << 1 | 1] += lazy[id]; lazy[id << 1] += lazy[id]; lazy[id << 1 | 1] += lazy[id]; lazy[id] = 0; } void up(int id, int l, int r, int u, int v, int val) { if (l > v or r < u) return; if (u <= l and r <= v) { st[id] += val; lazy[id] += val; return; } down(id); int mid = (l + r) >> 1; up(id << 1, l, mid, u, v, val); up(id << 1 | 1, mid + 1, r, u, v, val); st[id] = max(st[id << 1], st[id << 1 | 1]); } int get(int id, int l, int r, int u, int v) { if (l > v or r < u) return 0; if (u <= l and r <= v) return st[id]; down(id); int mid = (l + r) >> 1; return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v)); } int get(int idx, int l, int r, int val) { if(st[idx] < val) return -1; if(l == r) return l; down(idx); int mid = l + r >> 1; if(st[idx << 1] >= val) return get(idx << 1, l, mid, val); return get(idx << 1 | 1, mid + 1, r, val); } main() { #define name "TASK" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; fo(i, 1, n) cin >> a[i]; sort(a + 1, a + n + 1); // fo(i, 1, n) cout << a[i] << ' '; // en; fo(i, 1, n) up(1, 1, n, i, i, a[i]); // fo(i, 1, n) cout << get(1, 1, n, i, i) << ' '; // en; // cout << get(1, 1, n, 4) << "\n"; while (q--) { char t; int l, r; cin >> t >> r >> l; if (t == 'F') { int lb = get(1, 1, n, l); int maxx = get(1, 1, n, lb, lb + r - 1); int ub = get(1, 1, n, maxx) - 1; // cout << lb << ' ' << maxx << "\n"; int ub1 = get(1, 1, n, maxx + 1) - 1; // cout << lb << ' ' << ub << ' ' << ub1 << "\n"; if (ub >= lb) up(1, 1, n, lb, ub, 1); int len; if (ub < lb) len = r; else len = r - (ub - lb + 1); up(1, 1, n, ub1 - len + 1, ub1, 1); // cout << ub << ' ' << lb << "\n"; // cout << ub1 << ' ' << len << "\n"; // fo(i, 1, n) cout << get(1, 1, n, i, i) << ' '; // en; } else { swap(l,r); // cout << l << ' ' << r << "\n"; int lb = get(1, 1, n, l); int ub = get(1, 1, n, r + 1); if (ub == -1) ub = n + 1; // cout << lb << ' ' << ub << "xxxx\n"; if (lb != -1) cout << ub - lb << "\n"; else cout << 0 << "\n"; } } }

Compilation message (stderr)

grow.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
grow.cpp:83:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |  int mid = l + r >> 1;
      |            ~~^~~
grow.cpp: At global scope:
grow.cpp:87:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main()
      | ^~~~
grow.cpp: In function 'int main()':
grow.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(name ".out", "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...