USACO Silver 2016 December - Counting Haybales

Author: Albert Zhu

Official Analysis


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


#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);


import java.util.*;
public class Haybales {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(""));
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!