# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
22099 |
2017-04-29T08:55:08 Z |
쀼쀼~(#1017, cki86201) |
None (KRIII5P_3) |
C++11 |
|
303 ms |
12248 KB |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;
const int MOD = 1e9 + 7;
int P[100010], N;
int xs[200020], xz;
int S[100010], D[100010];
int T[1<<19];
int C[1<<19];
void pushdown(int rt){
if(C[rt] != 1){
T[rt<<1] = (ll)T[rt<<1] * C[rt] % MOD;
C[rt<<1] = (ll)C[rt<<1] * C[rt] % MOD;
T[rt<<1|1] = (ll)T[rt<<1|1] * C[rt] % MOD;
C[rt<<1|1] = (ll)C[rt<<1|1] * C[rt] % MOD;
C[rt] = 1;
}
}
void add(int rt, int l, int r, int x, int v){
if(l == r){
T[rt] = (T[rt] + v) % MOD;
return;
}
pushdown(rt);
int m = (l + r) >> 1;
if(x <= m)add(rt<<1, l, m, x, v);
else add(rt<<1|1, m+1, r, x, v);
T[rt] = (T[rt<<1] + T[rt<<1|1]) % MOD;
}
void update(int rt, int l, int r, int s, int d, int v){
if(s <= l && r <= d){
T[rt] = (ll)T[rt] * v % MOD;
C[rt] = (ll)C[rt] * v % MOD;
return;
}
pushdown(rt);
int m = (l + r) >> 1;
if(s <= m) update(rt<<1, l, m, s, d, v);
if(m < d) update(rt<<1|1, m+1, r, s, d, v);
T[rt] = (T[rt<<1] + T[rt<<1|1]) % MOD;
}
int read(int rt, int l, int r, int s, int d){
if(s <= l && r <= d){
return T[rt];
}
pushdown(rt);
int m = (l + r) >> 1, res = 0;
if(s <= m) res = (res + read(rt<<1, l, m, s, d)) % MOD;
if(m < d) res = (res + read(rt<<1|1, m+1, r, s, d)) % MOD;
T[rt] = (T[rt<<1] + T[rt<<1|1]) % MOD;
return res;
}
void solve(){
scanf("%d", &N);
vector <pii> v;
int tn = 0;
rep(i, N){
scanf("%d%d", S+tn, D+tn);
if(S[tn] >= D[tn]) continue;
v.pb(pii(S[tn], 1));
v.pb(pii(D[tn], -1));
xs[xz++] = S[tn];
xs[xz++] = D[tn];
++tn;
}
N = tn;
sort(all(v));
sort(xs, xs+xz);
xz = (int)(unique(xs, xs+xz) - xs);
vector <pii> V;
rep(i, N){
int x = (int)(lower_bound(xs, xs+xz, S[i]) - xs);
int y = (int)(lower_bound(xs, xs+xz, D[i]) - xs);
V.pb(pii(x, y));
}
P[1] = 1;
for(int i=2;i<=N;i++)P[i] = (2 * P[i-1] + 1) % MOD;
ll ans = 0;
for(int i=0, c=0;i<sz(v);i++){
c += v[i].Se;
if(i+1 < sz(v) && v[i].Fi != v[i+1].Fi){
ans = (ans + (ll)(v[i+1].Fi - v[i].Fi) * P[c]) % MOD;
}
}
printf("%lld ", ans);
sort(all(V));
rep(i, 1<<19)C[i] = 1;
for(int i=0;i<sz(V);i++){
int t = read(1, 0, xz - 1, V[i].Se, xz - 1);
add(1, 0, xz - 1, V[i].Se, (t + 1) % MOD);
update(1, 0, xz - 1, V[i].Fi + 1, V[i].Se - 1, 2);
}
printf("%d\n", read(1, 0, xz - 1, 0, xz - 1));
}
int main(){
int Tc = 1; //scanf("%d\n", &Tc);
for(int tc=1;tc<=Tc;tc++){
solve();
}
return 0;
}
Compilation message
i.cpp: In function 'void solve()':
i.cpp:91:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
i.cpp:95:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", S+tn, D+tn);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8072 KB |
Output is correct |
2 |
Correct |
0 ms |
8072 KB |
Output is correct |
3 |
Correct |
0 ms |
8072 KB |
Output is correct |
4 |
Correct |
0 ms |
8072 KB |
Output is correct |
5 |
Correct |
0 ms |
8072 KB |
Output is correct |
6 |
Correct |
9 ms |
8664 KB |
Output is correct |
7 |
Correct |
9 ms |
8664 KB |
Output is correct |
8 |
Correct |
6 ms |
8664 KB |
Output is correct |
9 |
Correct |
6 ms |
8664 KB |
Output is correct |
10 |
Correct |
13 ms |
8664 KB |
Output is correct |
11 |
Correct |
99 ms |
12248 KB |
Output is correct |
12 |
Correct |
99 ms |
12248 KB |
Output is correct |
13 |
Correct |
99 ms |
12248 KB |
Output is correct |
14 |
Correct |
99 ms |
12248 KB |
Output is correct |
15 |
Correct |
99 ms |
12248 KB |
Output is correct |
16 |
Correct |
153 ms |
10200 KB |
Output is correct |
17 |
Correct |
143 ms |
10200 KB |
Output is correct |
18 |
Correct |
163 ms |
10200 KB |
Output is correct |
19 |
Correct |
136 ms |
10200 KB |
Output is correct |
20 |
Correct |
106 ms |
10200 KB |
Output is correct |
21 |
Correct |
266 ms |
12248 KB |
Output is correct |
22 |
Correct |
296 ms |
12248 KB |
Output is correct |
23 |
Correct |
279 ms |
12248 KB |
Output is correct |
24 |
Correct |
266 ms |
12248 KB |
Output is correct |
25 |
Correct |
106 ms |
12248 KB |
Output is correct |
26 |
Correct |
256 ms |
12248 KB |
Output is correct |
27 |
Correct |
243 ms |
12248 KB |
Output is correct |
28 |
Correct |
226 ms |
12248 KB |
Output is correct |
29 |
Correct |
223 ms |
12248 KB |
Output is correct |
30 |
Correct |
216 ms |
12248 KB |
Output is correct |
31 |
Correct |
216 ms |
12248 KB |
Output is correct |
32 |
Correct |
196 ms |
12248 KB |
Output is correct |
33 |
Correct |
179 ms |
12248 KB |
Output is correct |
34 |
Correct |
173 ms |
12248 KB |
Output is correct |
35 |
Correct |
159 ms |
12248 KB |
Output is correct |
36 |
Correct |
303 ms |
12248 KB |
Output is correct |
37 |
Correct |
269 ms |
12248 KB |
Output is correct |
38 |
Correct |
279 ms |
12248 KB |
Output is correct |
39 |
Correct |
256 ms |
12248 KB |
Output is correct |
40 |
Correct |
276 ms |
12248 KB |
Output is correct |
41 |
Correct |
0 ms |
8072 KB |
Output is correct |
42 |
Correct |
3 ms |
8072 KB |
Output is correct |
43 |
Correct |
3 ms |
8212 KB |
Output is correct |
44 |
Correct |
6 ms |
8212 KB |
Output is correct |
45 |
Correct |
83 ms |
10200 KB |
Output is correct |
46 |
Correct |
96 ms |
10200 KB |
Output is correct |
47 |
Correct |
86 ms |
10200 KB |
Output is correct |
48 |
Correct |
179 ms |
12248 KB |
Output is correct |
49 |
Correct |
193 ms |
12248 KB |
Output is correct |
50 |
Correct |
189 ms |
12248 KB |
Output is correct |