Submission #22304844


Source Code Expand

#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     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, Q, L[201010], R[201010], A[201010], B[201010];
int ans[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;
	rep(i, 0, N - 1)cin >> L[i] >> R[i];
	rep(i, 0, Q) cin >> A[i] >> B[i], B[i]--;

	map<int, map<int, vector<int>>> que;
	rep(i, 0, N - 1) {
		que[L[i]][0].push_back(i);
		que[R[i] + 1][1].push_back(i);
	}
	rep(i, 0, Q) que[A[i]][2].push_back(i);

	set<int> ng;
	ng.insert(-1);
	rep(i, 0, N - 1) ng.insert(i);
	ng.insert(N - 1);

	fore(q, que) {
		int age = q.first;
		fore(i, q.second[0]) ng.erase(i);
		fore(i, q.second[1]) ng.insert(i);

		fore(i, q.second[2]) {
			auto ite = ng.lower_bound(B[i]);
			ite--;
			int L = *ite + 1;

			ite = ng.lower_bound(B[i]);
			int R = *ite;

			ans[i] = R - L + 1;
		}
	}

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





Submission Info

Submission Time
Task N - Travel Agency
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 2184 Byte
Status AC
Exec Time 1477 ms
Memory 233648 KiB

Compile Error

./Main.cpp: In function ‘void _main()’:
./Main.cpp:57:7: warning: unused variable ‘age’ [-Wunused-variable]
   57 |   int age = q.first;
      |       ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 2
AC × 22
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All core_based_random_00.txt, core_based_random_01.txt, core_based_random_02.txt, core_based_random_03.txt, core_based_random_04.txt, core_based_random_05.txt, extreme_00.txt, handmade_00.txt, max_00.txt, max_01.txt, max_02.txt, max_03.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
core_based_random_00.txt AC 1210 ms 204068 KiB
core_based_random_01.txt AC 1232 ms 205036 KiB
core_based_random_02.txt AC 220 ms 47000 KiB
core_based_random_03.txt AC 416 ms 84776 KiB
core_based_random_04.txt AC 179 ms 40080 KiB
core_based_random_05.txt AC 681 ms 127604 KiB
extreme_00.txt AC 762 ms 232600 KiB
handmade_00.txt AC 7 ms 3552 KiB
max_00.txt AC 1270 ms 233648 KiB
max_01.txt AC 1264 ms 233588 KiB
max_02.txt AC 1244 ms 232696 KiB
max_03.txt AC 1245 ms 233028 KiB
random_00.txt AC 312 ms 77892 KiB
random_01.txt AC 912 ms 158776 KiB
random_02.txt AC 1477 ms 233068 KiB
random_03.txt AC 1457 ms 232896 KiB
random_04.txt AC 265 ms 58148 KiB
random_05.txt AC 663 ms 127504 KiB
random_06.txt AC 73 ms 19692 KiB
random_07.txt AC 684 ms 129100 KiB
sample_01.txt AC 6 ms 3536 KiB
sample_02.txt AC 3 ms 3596 KiB