답안 #61183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61183 2018-07-25T10:09:14 Z Flugan42 Boat (APIO16_boat) C++14
31 / 100
1353 ms 158928 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double lld;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define per(i,a,b) for(ll i = a; i >= b; i--)
#define inf 1000000000000000000
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto a : x)

const ll mod = 1000000007;
ll n;
vi a,b,s,v;
set<ll> vals;

class segT {
private:
  ll n;
  vi tree,A;
  ll left(ll v) { return 2*v; }
  ll right(ll v) { return 2*v+1; }
  void build(ll p, ll l, ll r){
    if (l == r) tree[p] = (A[l]%mod);
    else {
      build(left(p),l,(l+r)/2);
      build(right(p),(l+r)/2+1,r);
      tree[p] = (tree[left(p)]+tree[right(p)])%mod;
    }
  }
  ll rsq(ll p, ll l, ll r, ll i, ll j){
    if (l > j || r < i) return 0;
    if (i <= l && r <= j) return (tree[p]%mod);
    ll p1 = rsq(left(p),l,(l+r)/2,i,j);
    ll p2 = rsq(right(p),(l+r)/2+1,r,i,j);
    return (p1+p2)%mod;
  }
  void update(ll p, ll l, ll r, ll i, ll val){
    if (i < l || r < i) return;
    if (l == r) {
      tree[p] = (A[l]%mod);
    } else {
      update(left(p),l,(l+r)/2,i,val);
      update(right(p),(l+r)/2+1,r,i,val);
      tree[p] = (tree[left(p)]+tree[right(p)])%mod;
    }
  }
public:
  void build(vi &_a){
    n = sz(_a);
    A = _a;
    tree.assign(4*n+10,0);
  }
  ll rsq(ll i, ll j) { return rsq(1,0,n-1,i,j); }
  void update(ll i, ll val){
    A[i] = (val%mod);
    update(1,0,n-1,i,val);
  }
} ;

int main(){
  cin >> n;
  a.assign(n,0); b.assign(n,0);
  rep(i,0,n) {
    cin >> a[i] >> b[i];
    assert(b[i]-a[i] < 1000010);
    per(j,b[i],a[i]) { vals.insert(j); s.push_back(j); }
  }

  trav(x,vals) v.push_back(x);
  sort(all(v));
  vi dp; dp.assign(sz(v),0);
  segT mytree;
  mytree.build(dp);

  unordered_map<ll,ll> inv;
  rep(i,0,sz(v)){ inv.insert(make_pair(v[i],i)); }
  rep(i,0,sz(s)){
    if (inv[s[i]] == 0) {
      dp[inv[s[i]]] = ((dp[inv[s[i]]]+1)%mod);
      mytree.update(inv[s[i]],dp[inv[s[i]]]);
    }
    else {
      dp[inv[s[i]]] = (1+dp[inv[s[i]]]+mytree.rsq(0,inv[s[i]]-1))%mod;
      mytree.update(inv[s[i]],dp[inv[s[i]]]);
    }
  //  cout << s[i] << " " << inv[s[i]] << " " << dp[inv[s[i]]] << endl;
  }
  ll res = 0;
  rep(i,0,sz(dp)) { res = (res+dp[i])%mod; }
  cout << res << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 5 ms 556 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 4 ms 616 KB Output is correct
6 Correct 3 ms 692 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 3 ms 692 KB Output is correct
10 Correct 4 ms 692 KB Output is correct
11 Correct 3 ms 692 KB Output is correct
12 Correct 3 ms 692 KB Output is correct
13 Correct 4 ms 692 KB Output is correct
14 Correct 5 ms 692 KB Output is correct
15 Correct 3 ms 692 KB Output is correct
16 Correct 5 ms 692 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 3 ms 692 KB Output is correct
19 Correct 4 ms 692 KB Output is correct
20 Correct 5 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 5 ms 556 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 4 ms 616 KB Output is correct
6 Correct 3 ms 692 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 3 ms 692 KB Output is correct
10 Correct 4 ms 692 KB Output is correct
11 Correct 3 ms 692 KB Output is correct
12 Correct 3 ms 692 KB Output is correct
13 Correct 4 ms 692 KB Output is correct
14 Correct 5 ms 692 KB Output is correct
15 Correct 3 ms 692 KB Output is correct
16 Correct 5 ms 692 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 3 ms 692 KB Output is correct
19 Correct 4 ms 692 KB Output is correct
20 Correct 5 ms 692 KB Output is correct
21 Correct 539 ms 9040 KB Output is correct
22 Correct 649 ms 9040 KB Output is correct
23 Correct 665 ms 9040 KB Output is correct
24 Correct 597 ms 9040 KB Output is correct
25 Correct 615 ms 9040 KB Output is correct
26 Correct 619 ms 9080 KB Output is correct
27 Correct 619 ms 9080 KB Output is correct
28 Correct 620 ms 9080 KB Output is correct
29 Correct 597 ms 9080 KB Output is correct
30 Correct 1247 ms 158660 KB Output is correct
31 Correct 1231 ms 158660 KB Output is correct
32 Correct 1220 ms 158928 KB Output is correct
33 Correct 1159 ms 158928 KB Output is correct
34 Correct 1353 ms 158928 KB Output is correct
35 Correct 1265 ms 158928 KB Output is correct
36 Correct 1214 ms 158928 KB Output is correct
37 Correct 1131 ms 158928 KB Output is correct
38 Correct 1157 ms 158928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 158928 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 5 ms 556 KB Output is correct
4 Correct 4 ms 612 KB Output is correct
5 Correct 4 ms 616 KB Output is correct
6 Correct 3 ms 692 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 3 ms 692 KB Output is correct
10 Correct 4 ms 692 KB Output is correct
11 Correct 3 ms 692 KB Output is correct
12 Correct 3 ms 692 KB Output is correct
13 Correct 4 ms 692 KB Output is correct
14 Correct 5 ms 692 KB Output is correct
15 Correct 3 ms 692 KB Output is correct
16 Correct 5 ms 692 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 3 ms 692 KB Output is correct
19 Correct 4 ms 692 KB Output is correct
20 Correct 5 ms 692 KB Output is correct
21 Correct 539 ms 9040 KB Output is correct
22 Correct 649 ms 9040 KB Output is correct
23 Correct 665 ms 9040 KB Output is correct
24 Correct 597 ms 9040 KB Output is correct
25 Correct 615 ms 9040 KB Output is correct
26 Correct 619 ms 9080 KB Output is correct
27 Correct 619 ms 9080 KB Output is correct
28 Correct 620 ms 9080 KB Output is correct
29 Correct 597 ms 9080 KB Output is correct
30 Correct 1247 ms 158660 KB Output is correct
31 Correct 1231 ms 158660 KB Output is correct
32 Correct 1220 ms 158928 KB Output is correct
33 Correct 1159 ms 158928 KB Output is correct
34 Correct 1353 ms 158928 KB Output is correct
35 Correct 1265 ms 158928 KB Output is correct
36 Correct 1214 ms 158928 KB Output is correct
37 Correct 1131 ms 158928 KB Output is correct
38 Correct 1157 ms 158928 KB Output is correct
39 Runtime error 3 ms 158928 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -