Submission #22168

# Submission time Handle Problem Language Result Execution time Memory
22168 2017-04-29T13:45:05 Z _(:3」∠)_(#1025, xdoju) None (KRIII5P_3) C++11
7 / 7
329 ms 13416 KB
#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;
}

Compilation message

i.cpp: In function 'int main()':
i.cpp:24:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int N; scanf("%d", &N);
                         ^
i.cpp:28:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int s, e; scanf("%d%d", &s, &e);
                                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1960 KB Output is correct
2 Correct 0 ms 1960 KB Output is correct
3 Correct 0 ms 1960 KB Output is correct
4 Correct 0 ms 1960 KB Output is correct
5 Correct 0 ms 1960 KB Output is correct
6 Correct 6 ms 2252 KB Output is correct
7 Correct 6 ms 2252 KB Output is correct
8 Correct 6 ms 2252 KB Output is correct
9 Correct 6 ms 2252 KB Output is correct
10 Correct 6 ms 2252 KB Output is correct
11 Correct 76 ms 4692 KB Output is correct
12 Correct 69 ms 4692 KB Output is correct
13 Correct 83 ms 4692 KB Output is correct
14 Correct 79 ms 4692 KB Output is correct
15 Correct 89 ms 4692 KB Output is correct
16 Correct 133 ms 7640 KB Output is correct
17 Correct 139 ms 7640 KB Output is correct
18 Correct 139 ms 7772 KB Output is correct
19 Correct 183 ms 7640 KB Output is correct
20 Correct 63 ms 3416 KB Output is correct
21 Correct 313 ms 13416 KB Output is correct
22 Correct 329 ms 13416 KB Output is correct
23 Correct 289 ms 13416 KB Output is correct
24 Correct 316 ms 13416 KB Output is correct
25 Correct 83 ms 4692 KB Output is correct
26 Correct 263 ms 9984 KB Output is correct
27 Correct 193 ms 8136 KB Output is correct
28 Correct 163 ms 6288 KB Output is correct
29 Correct 166 ms 5892 KB Output is correct
30 Correct 163 ms 5496 KB Output is correct
31 Correct 139 ms 4968 KB Output is correct
32 Correct 109 ms 4692 KB Output is correct
33 Correct 116 ms 4692 KB Output is correct
34 Correct 89 ms 4692 KB Output is correct
35 Correct 89 ms 4692 KB Output is correct
36 Correct 269 ms 13416 KB Output is correct
37 Correct 279 ms 13416 KB Output is correct
38 Correct 303 ms 13416 KB Output is correct
39 Correct 289 ms 13416 KB Output is correct
40 Correct 313 ms 13416 KB Output is correct
41 Correct 0 ms 2092 KB Output is correct
42 Correct 0 ms 2092 KB Output is correct
43 Correct 3 ms 2252 KB Output is correct
44 Correct 3 ms 2252 KB Output is correct
45 Correct 66 ms 5396 KB Output is correct
46 Correct 83 ms 5396 KB Output is correct
47 Correct 69 ms 5396 KB Output is correct
48 Correct 169 ms 8664 KB Output is correct
49 Correct 186 ms 8664 KB Output is correct
50 Correct 166 ms 8664 KB Output is correct