USACO Silver 2016 December - Counting Haybales

Author: Albert Zhu


Official Analysis

Implementation

Time Complexity: O((N+Q)logN)\mathcal{O}((N+Q)\log N)

C++

#include <bits/stdc++.h>
using namespace std;
void setIO(string prob="") {
if (!prob.empty()) {
freopen((prob + ".in").c_str(), "r", stdin);
freopen((prob + ".out").c_str(), "w", stdout);
}
}

Java

import java.util.*;
import java.io.*;
public class Haybales {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader("haybales.in"));
PrintWriter pw = new PrintWriter("haybales.out");
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!