Submission #6931414


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/













int N, Q; ll D[501010], T[501010], L[501010], R[501010];
int ans[501010];
//---------------------------------------------------------------------------------------------------
int get(ll top, ll L, ll R, vector<ll> &ds) {
	// T - R≦D[i]≦T - L

	int lft = lower_bound(all(ds), top - R) - ds.begin();
	int rht = upper_bound(all(ds), top - L) - ds.begin();

	int res = rht - lft;
	if (L <= top and top <= R) res++;

	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;
	rep(i, 0, N) cin >> D[i];
	rep(i, 0, Q) cin >> T[i] >> L[i] >> R[i];

	rep(i, 1, N) D[i] += D[i - 1];

	vector<int> ord;
	rep(i, 0, Q) ord.push_back(i);
	sort(all(ord), [&](int a, int b) {return T[a] < T[b]; });

	int moved = 0;
	vector<ll> ds;
	rep(_q, 0, Q) {
		int q = ord[_q];

		while (moved < N and D[moved] <= T[q]) {
			ds.push_back(D[moved]);
			moved++;
		}

		ans[q] = get(T[q], L[q], R[q], ds);
	}

	rep(q, 0, Q) printf("%d\n", ans[q]);
}






Submission Info

Submission Time
Task E - 最悪の教頭 (Worst Head Teacher)
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2344 Byte
Status AC
Exec Time 384 ms
Memory 26988 KB

Judge Result

Set Name Sample 1 Sample 2 Sample 3 Subtask 1 Subtask 2 Subtask 3
Score / Max Score 0 / 0 0 / 0 0 / 0 15 / 15 16 / 16 69 / 69
Status
AC × 1
AC × 1
AC × 1
AC × 10
AC × 6
AC × 21
Set Name Test Cases
Sample 1 sample-01.txt
Sample 2 sample-02.txt
Sample 3 sample-03.txt
Subtask 1 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt
Subtask 2 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt
Subtask 3 sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 6400 KB
01-02.txt AC 3 ms 6400 KB
01-03.txt AC 3 ms 6400 KB
01-04.txt AC 3 ms 6400 KB
01-05.txt AC 3 ms 6400 KB
01-06.txt AC 3 ms 6400 KB
01-07.txt AC 3 ms 6400 KB
01-08.txt AC 3 ms 6400 KB
02-01.txt AC 278 ms 23024 KB
02-02.txt AC 359 ms 26988 KB
02-03.txt AC 288 ms 23536 KB
02-04.txt AC 357 ms 26988 KB
02-05.txt AC 252 ms 22000 KB
02-06.txt AC 271 ms 23536 KB
03-01.txt AC 384 ms 26348 KB
03-02.txt AC 381 ms 26348 KB
03-03.txt AC 382 ms 26348 KB
03-04.txt AC 381 ms 26348 KB
sample-01.txt AC 2 ms 6400 KB
sample-02.txt AC 2 ms 6400 KB
sample-03.txt AC 2 ms 6400 KB