Submission #1104396

#TimeUsernameProblemLanguageResultExecution timeMemory
1104396TrendBattlesPlahte (COCI17_plahte)C++14
0 / 160
2075 ms6104 KiB
#include <bits/stdc++.h> using namespace std; using lli = int64_t; #define INFILE "present.inp" #define OUTFILE "present.ans" struct Rectangle { int a, b, c, d; Rectangle(int _a = 0, int _b = 0, int _c = 0, int _d = 0): a(_a), b(_b), c(_c), d(_d) {} }; void compress(vector <int>& DIFF_X, vector <int>& DIFF_Y, vector <Rectangle>& rect, vector <pair <int, int>>& points, vector <int>& color) { for (Rectangle& R : rect) { DIFF_X.push_back(R.a); DIFF_X.push_back(R.c); DIFF_Y.push_back(R.b); DIFF_Y.push_back(R.d); } for (pair <int, int>& P : points) { DIFF_X.push_back(P.first); DIFF_Y.push_back(P.second); } sort(DIFF_X.begin(), DIFF_X.end()); sort(DIFF_Y.begin(), DIFF_Y.end()); DIFF_X.erase(unique(DIFF_X.begin(), DIFF_X.end()), DIFF_X.end()); DIFF_Y.erase(unique(DIFF_Y.begin(), DIFF_Y.end()), DIFF_Y.end()); for (Rectangle& R : rect) { R.a = lower_bound(DIFF_X.begin(), DIFF_X.end(), R.a) - DIFF_X.begin(); R.c = lower_bound(DIFF_X.begin(), DIFF_X.end(), R.c) - DIFF_X.begin(); R.b = lower_bound(DIFF_Y.begin(), DIFF_Y.end(), R.b) - DIFF_Y.begin(); R.d = lower_bound(DIFF_Y.begin(), DIFF_Y.end(), R.d) - DIFF_Y.begin(); } for (pair <int, int>& P : points) { P.first = lower_bound(DIFF_X.begin(), DIFF_X.end(), P.first) - DIFF_X.begin(); P.second = lower_bound(DIFF_Y.begin(), DIFF_Y.end(), P.second) - DIFF_Y.begin(); } vector <int> diff_color = color; sort(diff_color.begin(), diff_color.end()); diff_color.erase(unique(diff_color.begin(), diff_color.end()), diff_color.end()); for (int& x : color) { x = lower_bound(diff_color.begin(), diff_color.end(), x) - diff_color.begin(); } } struct Events { int p_x, p_y, pos; Events(int p_x = 0, int p_y = 0, int s = -1): p_x(p_x), p_y(p_y), pos(s) {} bool operator < (const Events& other) const { if (p_x != other.p_x) return p_x < other.p_x; if (p_y != other.p_y) return p_y < other.p_y; return pos < other.pos; } }; int time_passed = -1; //int debugging = false; struct SegmentTree { vector <int> node, lazy, last_update, last_lazy; int N; SegmentTree(int N): N(N), node(N << 2, -1), lazy(N << 2, -1), last_update(N << 2, -1), last_lazy(N << 2, -1) {} void Apply(int v, int id) { node[v] = id; lazy[v] = id; } void Push(int v) { if (lazy[v] == -1) return; for (int child : {v << 1, v << 1 | 1}) { Apply(child, lazy[v]); last_update[child] = last_lazy[child] = last_lazy[v]; } lazy[v] = last_lazy[v] = -1; } void update_range(int v, int tl, int tr, int l, int r, int id) { if (l > r) return; if (l == tl and r == tr) { Apply(v, id); last_update[v] = last_lazy[v] = time_passed; return; } int tm = (tl + tr) >> 1; Push(v); update_range(v << 1, tl, tm, l, min(r, tm), id); update_range(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r, id); last_update[v] = max(last_update[v << 1], last_update[v << 1 | 1]); } void update_range(int l, int r, int id) { update_range(1, 0, N - 1, l, r, id); } int get_val(int pos) { int v = 1, l = 0, r = N - 1; while (l < r) { Push(v); int mid = (l + r) >> 1; if (pos <= mid) { r = mid; v <<= 1; } else { l = mid + 1; v = v << 1 | 1; } } return node[v]; } int get_latest(int v, int tl, int tr, int l, int r) { if (l > r) return -1; //if (debugging) cerr << v << ' ' << tl << ' ' << tr << ' ' << l << ' ' << r << '\n'; if (l == tl and r == tr) return last_update[v]; Push(v); //if (debugging) cerr << "DONE PUSHING\n"; int tm = (tl + tr) >> 1; return max( get_latest(v << 1, tl, tm, l, min(r, tm)), get_latest(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r) ); } int get_latest(int l, int r) { return get_latest(1, 0, N - 1, l, r); } }; int main() { ios::sync_with_stdio(0); cin.tie(0); if (fopen(INFILE, "r")) { freopen(INFILE, "r", stdin); freopen(OUTFILE, "w", stdout); } int N, Q; cin >> N >> Q; vector <Rectangle> rect(N); for (Rectangle& R : rect) cin >> R.a >> R.b >> R.c >> R.d; vector <pair <int, int>> points(Q); vector <int> color; for (pair <int, int>& P : points) { cin >> P.first >> P.second; int x; cin >> x; color.push_back(x); } vector <int> DIFF_X, DIFF_Y; compress(DIFF_X, DIFF_Y, rect, points, color); for (int i = 0; i < N; ++i) { Rectangle& R = rect[i]; set <int> T; for (int j = 0; j < Q; ++j) { if (points[j].first < R.a or points[j].first > R.c) continue; if (points[j].second < R.b or points[j].second > R.d) continue; T.insert(color[j]); } cout << (int) T.size() << '\n'; } return 0; }

Compilation message (stderr)

plahte.cpp: In constructor 'SegmentTree::SegmentTree(int)':
plahte.cpp:70:9: warning: 'SegmentTree::N' will be initialized after [-Wreorder]
   70 |     int N;
      |         ^
plahte.cpp:69:18: warning:   'std::vector<int> SegmentTree::node' [-Wreorder]
   69 |     vector <int> node, lazy, last_update, last_lazy;
      |                  ^~~~
plahte.cpp:71:5: warning:   when initialized here [-Wreorder]
   71 |     SegmentTree(int N): N(N), node(N << 2, -1), lazy(N << 2, -1), last_update(N << 2, -1), last_lazy(N << 2, -1) {}
      |     ^~~~~~~~~~~
plahte.cpp: In function 'int main()':
plahte.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(INFILE, "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
plahte.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(OUTFILE, "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...