Submission #1312396

#TimeUsernameProblemLanguageResultExecution timeMemory
1312396sakuda00Inspections (NOI23_inspections)C++20
11 / 100
2 ms1940 KiB
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <unordered_map>
using namespace std;
using ll = long long;
int left(int v, set<int>& st) {
	auto itr = st.lower_bound(v);
	if (itr == st.begin()) return -1;
	itr--;
	return (*itr);
}
int right(int v, set<int>& st) {
	auto itr = st.upper_bound(v);
	if (itr == st.end()) return -1;
	return (*itr);
}
ll dis(int x, int y, vector<ll>& S, vector<ll>& L, vector<ll>& R) {
	ll s = (y == 0 ? 0 : S[y - 1]) - S[x];
	return s-L[y]+R[x];
}
int sear(ll x, vector<ll>& value) {
	auto itr = upper_bound(value.begin(),value.end(), x);
	itr--;
	return (itr - value.begin());
}

vector<ll>  naive(int N, int M, vector<ll> L, vector<ll> R, vector<ll> S) {
	
	int Q=  S.size();
	vector<ll> res(Q, 0);
	vector<int> lst;
	for (int i = 0;i < M;i++) for (int x = L[i];x <= R[i];x++) lst.push_back(x);
	vector<int> pl(N + 1, -1);
	for (int i = 0;i < lst.size();i++) {
		int v = lst[i];
		if (pl[v] != -1) {
			int d = i - pl[v] - 1;
			for (int i = 0;i < Q;i++) if (S[i]<=  d) res[i]++;
		}
		pl[v] = i;
	}

	return res;
}
int main() {
	int N, M, Q;cin >> N >> M >> Q;
	if (N > 200 || M > 200 || Q > 200) {
		return 0;
	}
	vector<ll> L(M), R(M);

	vector<vector<int>> IN(N + 1), OUT(N + 2);
	for (int i = 0;i < M;i++) {
		cin >> L[i] >> R[i];
		IN[L[i]].push_back(i);
		OUT[R[i] + 1].push_back(i);
	}
	vector<ll> S(M);
	ll sm = 0;
	for (int i = 0;i < M;i++) {
		sm += (R[i] - L[i] + 1);
		S[i] = sm;
	}
	set<int> id;
	map<pair<int, int>, ll> pls;
	vector<ll> QRY(Q);
	vector<ll> value = {-(1LL << 60)};
	for (int i = 0;i < Q;i++) {
		cin >> QRY[i];
		value.push_back(QRY[i]);
	}
	sort(value.begin(), value.end());
	value.erase(unique(value.begin(),value.end()), value.end());
	int T = value.size();
	vector<ll> res(T + 1, 0);
	for (int i = 1;i <= N;i++) {

		for (auto v : OUT[i]) {
			if (id.find(v) == id.end()) continue;
			int lid = left(v, id);
			if (lid != -1) {
				//cout << lid << " " << v << " " << dis(lid, v, S, L, R) << endl;
				pls[{lid, v}] = i;
				ll d = dis(lid, v, S, L, R);
				res[0] -= N - i + 1;
				res[sear(d, value) + 1] += N - i + 1;
			} 
			int rid = right(v, id);
			if (rid != -1) {
				//cout << rid << " " << v << " " << dis(v, rid, S, L, R) << endl;
				pls[{v, rid}] = i;
				res[0] -= N - i + 1;
				ll d = dis(v, rid, S, L,R);
				res[sear(d, value) + 1] += N - i + 1;
			}
			if (lid != -1 and rid != -1) {
				//cout << "REV " << lid << " " << rid << " " << dis(lid, rid, S, L, R) << endl;
				ll d=  dis(lid, rid, S, L, R);
				res[0] += N - i + 1;
				res[sear(d, value) + 1] -= N - i + 1;
			}
			id.erase(v);
		}
		//cout << i << endl;
		for (auto v : IN[i]) {
			if (id.find(v) != id.end()) continue;
			int lid = left(v, id);
			int rid = right(v, id);

			if (lid != -1 and rid != -1) {
				//cout << "ERR " << lid << " " << rid << " " << dis(lid, rid, S, L, R) << endl;
				ll d=  dis(lid, rid, S, L, R);
				res[0] -= N - i + 1;
				res[sear(d, value) + 1] += N - i + 1;
			}
			if (lid != -1) {
				//cout <<"AD " << i << " " <<  lid << " " << v << " " << dis(lid, v, S, L, R) << endl;
				pls[{lid, v}] = i;
				ll d = dis(lid, v, S, L, R);
				res[0] += N - i + 1;
				res[sear(d, value) + 1] -= N - i + 1;
			} 
			if (rid != -1) {
				
				//cout << "ADR " << i << " " << rid << " " << v << " " << dis(v, rid, S, L, R) << endl;
				pls[{v, rid}] = i;
				res[0] += N - i + 1;
				ll d = dis(v, rid, S, L,R);
				res[sear(d, value) + 1] -= N - i + 1;
			}
			id.insert(v);

		}
		
	//	cout <<"RG" << " " << i << endl;
	//	for (auto v : id) cout <<v + 1 << " ";
	//	cout << endl;

		vector<ll> SS(T, 0);
		//ll sms = 0;
	//	cout << "SM" << endl;
		
	}

	sm = 0;
	for (int i = 0;i <= T;i++) {
		sm += res[i];
		res[i] = sm;
	}
	//cout <<"res" << endl;
	for (int i = 0;i < Q;i++) {
		int id = sear(QRY[i], value);
		cout << res[id] << " ";
	}
	cout << endl;
	/*
	cout << "naive" << endl;
	
	auto NV = naive(N, M, L, R, QRY);
	for (auto r : NV) {
		cout <<r << " ";

	}

	cout << endl;

	*/
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...