# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22168 | _(:3」∠)_ (#42) | 구간들 (KRIII5P_3) | C++11 | 329 ms | 13416 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <utility>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int MOD = 1000000007;
vector<pair<int, int> > p;
vector<int> xs; map<int, int> xi;
int tr[200010];
int pow2(int x){
int res = 1, pw = 2;
while(x > 0){
if(x % 2 == 1) res = 1LL * res * pw % MOD;
pw = 1LL * pw * pw % MOD; x /= 2;
}
return res;
}
int main(){
int N; scanf("%d", &N);
xs.push_back(-1);
for(; N--; ){
int s, e; scanf("%d%d", &s, &e);
if(s >= e) continue;
xs.push_back(s); xs.push_back(e);
p.push_back({e, s});
}
N = p.size();
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
int xc = (int)xs.size() - 1;
for(int i = 1; i <= xc; i++) xi[xs[i]] = i;
for(int i = 0; i < N; i++){
p[i].first = xi[p[i].first];
p[i].second = xi[p[i].second];
}
sort(p.begin(), p.end());
// distance sum
int ds = 0;
for(int i = xc, pi = N - 1; i > 1; i--){
while(pi >= 0 && p[pi].first == i){
for(int x = p[pi].second; x <= xc; x += x & -x) tr[x]++;
pi--;
}
int s = 0;
for(int x = i - 1; x > 0; x -= x & -x) s += tr[x];
ds += 1LL * (pow2(s) - 1) * (xs[i] - xs[i - 1]) % MOD;
if(ds >= MOD) ds -= MOD;
}
// number of sets
int cnt = 0;
for(int i = 1; i <= xc; i++) tr[i] = 0;
for(int i = N - 1; i >= 0; i--){
int s = 0;
for(int x = p[i].first - 1; x > 0; x -= x & -x) s += tr[x];
cnt += pow2(s); if(cnt >= MOD) cnt -= MOD;
for(int x = p[i].second; x <= xc; x += x & -x) tr[x]++;
}
printf("%d %d\n", ds, cnt);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |