# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22141 | 연습대회 팀 네임은 수정할 수 있을까? (#42) | 구간들 (KRIII5P_3) | C++14 | 149 ms | 5472 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <string.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<int, int> pi;
const int MAX_N = 1e5 + 100, MOD = 1e9 + 7;
int ab(int a, int b) {
int res = 1, val = a;
while(b) {
if(b%2) res = 1ll * res * val % MOD;
val = 1ll * val * val % MOD;
b/=2;
}
return res;
}
int N, Cnt[MAX_N * 2], RCnt[MAX_N * 2];
int main() {
vector<pi> Is;
vector<int> cor;
scanf("%d", &N);
for(int i=0; i<N; i++) {
int x, y; scanf("%d%d", &x, &y);
if(x >= y) continue;
Is.emplace_back(x, y);
cor.push_back(x); cor.push_back(y);
}
N = Is.size(); cor.push_back(-1); cor.push_back(1e9 + 10);
sort(cor.begin(), cor.end()); cor.erase(unique(cor.begin(), cor.end()), cor.end());
for(pi &e : Is) {
int &x = e.first, &y = e.second;
x = lower_bound(cor.begin(), cor.end(), x) - cor.begin();
y = lower_bound(cor.begin(), cor.end(), y) - cor.begin() - 1;
Cnt[x]++; Cnt[y+1]--;
RCnt[y]++; RCnt[y+1]--;
}
int cnt = 0, rcnt = 0;
int len = 0, ans = 0;
for(int l=0; l<cor.size(); l++) {
cnt += Cnt[l];
rcnt += RCnt[l];
len += 1ll * (ab(2, cnt) - 1) * (cor[l+1] - cor[l]) % MOD; len %= MOD;
ans += 1ll * (ab(2, rcnt) - 1) * ab(2, cnt-rcnt) % MOD; ans %= MOD;
}
printf("%d %d\n", len, ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |