# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22916 | dotorya | 구간들 (KRIII5P_3) | C++14 | 156 ms | 46568 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |