Editing
2016 Jan Platinum Problem 2 Mowing the Field
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== C++ === <pre> #include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; const int MAXN = 1 << 17; const int MAXV = 1 << 30; struct Node { int val; Node* child[2]; Node() : val(0), child{nullptr, nullptr} {} Node* get_child(int c) { if (!child[c]) { child[c] = new Node; } return child[c]; } void add(int x, int v, int lo, int hi) { val += v; if (hi - lo == 1) { return; } int mid = (lo + hi) / 2; if (x < mid) { get_child(0)->add(x, v, lo, mid); } else { get_child(1)->add(x, v, mid, hi); } } int query(int a, int b, int lo, int hi) { if (a <= lo && hi <= b) { return val; } else if (hi <= a || b <= lo) { return 0; } int mid = (lo + hi) / 2; return (child[0] ? child[0]->query(a, b, lo, mid) : 0) + (child[1] ? child[1]->query(a, b, mid, hi) : 0); } }; vector<Node> bit(MAXN); // Logically executes array[y].add(x, v) += v. void bit_add(int x, int y, int v) { for(unsigned j = y | MAXN; j < (MAXN << 1); j += j & -j) { bit[j ^ MAXN].add(x, v, 0, MAXV); } } // Returns the sum of array[i].query(x0, x1) for 0 <= i < y int bit_get(int x0, int x1, int y) { int ret = 0; for(int j = y - 1; y != 0; j &= j - 1) { ret += bit[j].query(x0, x1, 0, MAXV); if (!j) break; } return ret; } int main() { // Replace this with the actual file path freopen("mowing.in", "r", stdin); freopen("mowing.out", "w", stdout); ios_base::sync_with_stdio(false); int N; cin >> N; int T; cin >> T; vector<pair<int, int> > cells(N); for (int i = 0; i < N; i++) { cin >> cells[i].first >> cells[i].second; } // Will fill this section after explaining the approach return 0; } </pre>
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information