Submission #39665

#TimeUsernameProblemLanguageResultExecution timeMemory
39665farmersriceNuclearia (CEOI15_nuclearia)C++14
15 / 100
1000 ms241100 KiB
#include <bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #pragma GCC target ("avx,tune=native") //Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly /* TASK: hidden LANG: C++11 */ using namespace std; typedef long long ll; typedef pair<int, int> pair2; typedef pair<int, pair<int, int> > pair3; typedef pair<int, pair<int, pair<int, int> > > pair4; #define MAXN 200013 #define INF 1000000000000000000LL #define mp make_pair #define add push_back #define remove pop //only works for H = 1 case int n; int w, h, q; int x[MAXN], y[MAXN]; ll a[MAXN], b[MAXN]; //copy from radoslav11 coding library struct node_ap { ll sum, lazy, lazy_ap; node_ap() {sum = 0; lazy = 0; lazy_ap = 0;} node_ap(ll val) { sum = val; lazy = 0; lazy_ap = 0; } }; node_ap temp, broken; node_ap merge(node_ap l, node_ap r) { temp.sum = l.sum + r.sum; temp.lazy = 0; temp.lazy_ap = 0; return temp; } node_ap tr[4 * 2500013]; struct segment_tree_ap { //node_ap tr[4 * 2500013]; void update(int l, int r, int idx) { if (tr[idx].lazy) { tr[idx].sum += (r - l + 1) * tr[idx].lazy; if (l != r) { tr[2 * idx].lazy += tr[idx].lazy; tr[2 * idx + 1].lazy += tr[idx].lazy; } tr[idx].lazy = 0; } if (tr[idx].lazy_ap) { int mid = (l + r) >> 1; tr[idx].sum += (((ll)(r - l + 1)) * (r - l + 2) / 2) * tr[idx].lazy_ap; if(l != r) { tr[2 * idx].lazy_ap += tr[idx].lazy_ap; tr[2 * idx + 1].lazy_ap += tr[idx].lazy_ap; tr[2 * idx + 1].lazy += tr[idx].lazy_ap * (mid - l + 1); } tr[idx].lazy_ap = 0; } } void init(int l, int r, int idx) { if (l == r) { tr[idx] = node_ap(); return; } int mid = (l + r) >> 1; init(l, mid, 2 * idx); init(mid + 1, r, 2 * idx + 1); tr[idx] = merge(tr[2 * idx], tr[2 * idx + 1]); } void update(int qL, int qR, ll val, ll prog, int l, int r, int idx) { update(l, r, idx); if (qL > r || l > qR) return; if (qL <= l && r <= qR) { tr[idx].lazy += val + (l - qL) * prog; tr[idx].lazy_ap += prog; update(l, r, idx); return; } int mid = (l + r) >> 1; update(qL, qR, val, prog, l, mid, 2 * idx); update(qL, qR, val, prog, mid + 1, r, 2 * idx + 1); tr[idx] = merge(tr[2 * idx], tr[2 * idx + 1]); } node_ap query(int qL, int qR, int l, int r, int idx) { update(l, r, idx); if(l > qR || r < qL) return broken; if(qL <= l && r <= qR) return tr[idx]; int mid = (l + r) >> 1; return merge(query(qL, qR, l, mid, 2 * idx), query(qL, qR, mid + 1, r, 2 * idx + 1)); } }; segment_tree_ap t; int main() { //ios_base::sync_with_stdio(false); //cin.tie(NULL); scanf("%d%d", &w, &h); scanf("%d", &n); //cin >> w >> h; //assert(h == 1); //cin >> n; for (int i = 0; i < n; i++) { //cin >> x[i] >> y[i] >> a[i] >> b[i]; scanf("%d%d%lld%lld", &x[i], &y[i], &a[i], &b[i]); } t.init(0, w + 1, 1); //lol for (int i = 0; i < n; i++) { ll possible = (a[i] - 1) / b[i]; if (possible == 0) { t.update(x[i], x[i], a[i], 0, 0, w + 1, 1); continue; } int start = max(1, (int) (x[i] - possible)); int end = min(w, (int) (x[i] + possible)); //cout << "plant " << i << " found start, end " << start << ' ' << end //<< endl; ll startval = a[i] - ((x[i] - (ll)start) * b[i]); //cout << "startval is " << startval << endl; t.update(start, x[i], startval - b[i], b[i], 0, w + 1, 1); if (x[i] + 1 <= end) t.update(x[i] + 1, end, a[i], -b[i], 0, w + 1, 1); } scanf("%d", &q);//cin >> q; for (int i = 0; i < q; i++) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);//cin >> x1 >> y1 >> x2 >> y2; //cout << "boudns are " << x1 << ' ' << x2 << endl; ll sum = t.query(x1, x2, 0, w + 1, 1).sum; ll cells = x2 - x1 + 1; //cout << "query " << i << " found sum " << sum << " cells " << cells << endl; ll remainder = sum % cells; if ((cells % 2 == 0 && remainder >= cells / 2) || (cells % 2 == 1 && remainder > cells / 2)) { printf("%lld\n", 1 + sum / cells);//cout << 1 + sum / cells << endl; } else { printf("%lld\n", sum / cells);//cout << sum / cells << endl; } } return 0; }

Compilation message (stderr)

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:133:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &w, &h);
                       ^
nuclearia.cpp:134:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
nuclearia.cpp:141:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%lld%lld", &x[i], &y[i], &a[i], &b[i]);
                                                    ^
nuclearia.cpp:167:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);//cin >> q;
                 ^
nuclearia.cpp:170:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &x1, &y1, &x2, &y2);//cin >> x1 >> y1 >> x2 >> y2;
                                        ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...