Submission #1312405

#TimeUsernameProblemLanguageResultExecution timeMemory
1312405sakuda00Inspections (NOI23_inspections)C++20
Compilation error
0 ms0 KiB

# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")

#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() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int N, M, Q;cin >> N >> M >> Q;
	
	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;
	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);
	vector<int> prev(M, -1), nxt(M, -1);

	for (int i = 1;i <= N;i++) {

		for (auto v : OUT[i]) {
			if (id.find(v) == id.end()) continue;


			int lid = prev[v];
			int rid = nxt[v];
			
			if (lid != -1) {
				//cout << lid << " " << v << " " << dis(lid, v, S, L, R) << endl;
				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;
				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;

				nxt[lid] = rid;
				prev[rid] = lid;
			}
			if (lid != -1 and rid == -1) nxt[lid] = -1;
			if (rid != -1 and lid == -1) prev[rid] = -1;
			id.erase(v);
		}
		//cout << i << endl;
		for (auto v : IN[i]) {
			if (id.find(v) != id.end()) continue;
			auto itr = id.upper_bound(v);
			int lid = -1;int rid = -1;
			if (itr != id.end()) rid = *itr;
			if (itr != id.begin()) {
				itr--;
				lid = *itr;
			}
			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;
				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;
				res[0] += N - i + 1;
				ll d = dis(v, rid, S, L,R);
				res[sear(d, value) + 1] -= N - i + 1;
			}

			if (lid != -1) nxt[lid] = v;
			prev[v] = lid;
			nxt[v] = rid;
			if (rid != -1) prev[rid] = v;
			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 << "\n";
	/*
	cout << "naive" << endl;
	
	auto NV = naive(N, M, L, R, QRY);
	for (auto r : NV) {
		cout <<r << " ";

	}

	cout << endl;

	*/
	
}

Compilation message (stderr)

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from Main.cpp:6:
/usr/include/c++/13/bits/allocator.h: In destructor 'constexpr std::_Vector_base<long long int, std::allocator<long long int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long long int]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from Main.cpp:7:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~