Submission #22916

#TimeUsernameProblemLanguageResultExecution timeMemory
22916dotorya구간들 (KRIII5P_3)C++14
7 / 7
156 ms46568 KiB
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 1034567890123456789ll;
const db PI = acos(-1);
const db ERR = 1E-11;

int bit[300000];
void update(int p, int v) {
	for (p++; p <= IT_MAX; p += p & (-p)) bit[p] += v;
}
int getsum(int p) {
	int rv = 0;
	for (p++; p; p -= p & (-p)) rv += bit[p];
	return rv;
}

vector <pair<pll, int>> Vq;
vector <pll> in;
vector <ll> Vx;

ll po2[100050];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		if (t1 < t2) in.emplace_back(t1, t2);
		Vx.push_back(t1);
		Vx.push_back(t2);
	}
	sort(all(Vx));
	Vx.erase(unique(all(Vx)), Vx.end());
	for (auto &it : in) {
		it.first = lower_bound(all(Vx), it.first) - Vx.begin();
		it.second = lower_bound(all(Vx), it.second) - Vx.begin();
	}
	sort(all(in));

	ll a1 = 0, a2 = 0;
	po2[0] = 1;
	for (i = 1; i <= 100030; i++) po2[i] = po2[i - 1] * 2 % MOD;

	for (i = 0; i + 1 < Vx.size(); i++) {
		Vq.emplace_back(pll(i, i + 1), 1);
		Vq.emplace_back(pll(i, i + 1), 2);
		if (i) Vq.emplace_back(pll(i - 1, i + 1), 3);
	}
	sort(all(Vq));

	int p = 0;
	for (auto it : Vq) {
		ll t1 = it.first.first, t2 = it.first.second, t3 = it.second;
		while (p < in.size()) {
			if (in[p].first > t1) break;
			update(in[p++].second, 1);
		}

		ll v = getsum(Vx.size()) - getsum(t2 - 1);
		v = po2[v] - 1;

		if (t3 == 1) a1 = (a1 + v * (Vx[t1+1] - Vx[t1])) % MOD;
		if (t3 == 2) a2 = (a2 + v) % MOD;
		if (t3 == 3) a2 = (a2 + MOD - v) % MOD;
	}
	return !printf("%lld %lld\n", a1, a2);
}

Compilation message (stderr)

i.cpp:22:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)
 ^
i.cpp:23:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")
 ^
i.cpp: In function 'int main()':
i.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i + 1 < Vx.size(); i++) {
                    ^
i.cpp:99:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (p < in.size()) {
            ^
i.cpp:69:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
i.cpp:72:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t1, &t2);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...