답안 #22075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22075 2017-04-29T07:13:34 Z dotorya(#1012, dotorya) 구간들 (KRIII5P_3) C++14
7 / 7
349 ms 37184 KB
#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;

ll po2[300050];

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

map <int, int> Mx;
int Mv[200050];

vector <pii> in;

vector <pair<pii, int>> Vq;
int main() {
	int N, i;

	po2[0] = 1;
	for (i = 1; i <= 200000; i++) po2[i] = (po2[i - 1] * 2) % MOD;

	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);
	}
	N = in.size();
	if (!N) return !printf("0 0\n");
	
	sort(all(in));
	for (i = 0; i < N; i++) {
		Mx[in[i].first] = 0;
		Mx[in[i].second] = 0;
	}
	
	i = 0;
	for (auto &it : Mx) {
		it.second = ++i;
		Mv[i] = it.first;
	}
	for (i = 0; i < N; i++) {
		in[i].first = Mx[in[i].first];
		in[i].second = Mx[in[i].second];
	}

	int M = Mx.size();

	ll a1 = 0, a2 = 0;
	for (i = 1; i < M; i++) Vq.emplace_back(pii(i, i + 1), 1);
	for (i = 1; i < M; i++) {
		Vq.emplace_back(pii(i, i + 1), 2);
		if(i != 1) Vq.emplace_back(pii(i - 1, i + 1), 3);
	}
	sort(all(Vq));

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

		ll v = getsum(M) - getsum(it.first.second - 1);
		v = po2[v] - 1;

		if (it.second == 1) a1 = (a1 + (Mv[it.first.first + 1] - Mv[it.first.first]) * v) % MOD;
		if (it.second == 2) a2 = (a2 + v) % MOD;
		if (it.second == 3) a2 = (a2 - v + MOD) % MOD;
	}
	return !printf("%lld %lld\n", a1, a2);
}

Compilation message

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:113:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (p < in.size()) {
            ^
i.cpp:76:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
i.cpp:79:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t1, &t2);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7496 KB Output is correct
2 Correct 0 ms 7496 KB Output is correct
3 Correct 0 ms 7496 KB Output is correct
4 Correct 0 ms 7496 KB Output is correct
5 Correct 3 ms 7496 KB Output is correct
6 Correct 6 ms 7768 KB Output is correct
7 Correct 3 ms 7768 KB Output is correct
8 Correct 6 ms 7768 KB Output is correct
9 Correct 3 ms 7768 KB Output is correct
10 Correct 6 ms 7768 KB Output is correct
11 Correct 49 ms 9116 KB Output is correct
12 Correct 63 ms 9116 KB Output is correct
13 Correct 59 ms 9116 KB Output is correct
14 Correct 53 ms 9116 KB Output is correct
15 Correct 53 ms 9116 KB Output is correct
16 Correct 143 ms 22388 KB Output is correct
17 Correct 153 ms 22376 KB Output is correct
18 Correct 143 ms 22404 KB Output is correct
19 Correct 139 ms 22392 KB Output is correct
20 Correct 46 ms 9328 KB Output is correct
21 Correct 329 ms 37184 KB Output is correct
22 Correct 303 ms 37184 KB Output is correct
23 Correct 296 ms 37184 KB Output is correct
24 Correct 306 ms 37184 KB Output is correct
25 Correct 53 ms 9116 KB Output is correct
26 Correct 236 ms 24516 KB Output is correct
27 Correct 189 ms 18040 KB Output is correct
28 Correct 146 ms 16288 KB Output is correct
29 Correct 143 ms 13540 KB Output is correct
30 Correct 129 ms 13084 KB Output is correct
31 Correct 109 ms 11076 KB Output is correct
32 Correct 103 ms 9836 KB Output is correct
33 Correct 89 ms 9220 KB Output is correct
34 Correct 69 ms 9116 KB Output is correct
35 Correct 63 ms 9116 KB Output is correct
36 Correct 309 ms 37180 KB Output is correct
37 Correct 349 ms 37184 KB Output is correct
38 Correct 349 ms 37180 KB Output is correct
39 Correct 323 ms 37184 KB Output is correct
40 Correct 303 ms 37184 KB Output is correct
41 Correct 3 ms 7628 KB Output is correct
42 Correct 3 ms 7628 KB Output is correct
43 Correct 6 ms 8180 KB Output is correct
44 Correct 3 ms 8180 KB Output is correct
45 Correct 53 ms 15432 KB Output is correct
46 Correct 69 ms 15432 KB Output is correct
47 Correct 69 ms 15432 KB Output is correct
48 Correct 136 ms 23280 KB Output is correct
49 Correct 163 ms 23280 KB Output is correct
50 Correct 123 ms 23280 KB Output is correct