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!
=== Java === <pre> import java.io.*; import java.util.*; public class Main { static final int MAXN = 1 << 17; static final int MAXV = 1 << 30; static class Node { int val; Node[] child = new Node[2]; Node() { this.val = 0; } Node get_child(int c) { if (child[c] == null) { 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] != null ? child[0].query(a, b, lo, mid) : 0) + (child[1] != null ? child[1].query(a, b, mid, hi) : 0); } } static Node[] bit = new Node[MAXN]; // Logically executes array[y].add(x, v) += v. static void bit_add(int x, int y, int v) { for(int 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 static 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 == 0) break; } return ret; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("mowing.in")); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("mowing.out"))); int N = Integer.parseInt(br.readLine()); int T = Integer.parseInt(br.readLine()); for (int i = 0; i < N; i++) { // Read in the pairs and store in an appropriate data structure // Will need to implement the rest of the solution here } // Close the input/output streams br.close(); pw.close(); } } </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