답안 #61177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61177 2018-07-25T10:00:21 Z Flugan42 Boat (APIO16_boat) C++14
9 / 100
2000 ms 171152 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);

  map<ll,ll> inv;
  rep(i,0,sz(v)){ inv.insert(make_pair(v[i],i)); }
  rep(i,0,sz(s)){
    if (s[i] == 0) dp[inv[s[i]]] = ((dp[inv[s[i]]]+1)%mod);
    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 4 ms 376 KB Output is correct
2 Correct 4 ms 508 KB Output is correct
3 Correct 4 ms 524 KB Output is correct
4 Correct 4 ms 524 KB Output is correct
5 Correct 5 ms 524 KB Output is correct
6 Correct 4 ms 572 KB Output is correct
7 Correct 4 ms 572 KB Output is correct
8 Correct 3 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 4 ms 572 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 4 ms 772 KB Output is correct
15 Correct 5 ms 772 KB Output is correct
16 Correct 4 ms 772 KB Output is correct
17 Correct 5 ms 772 KB Output is correct
18 Correct 4 ms 772 KB Output is correct
19 Correct 4 ms 772 KB Output is correct
20 Correct 4 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 508 KB Output is correct
3 Correct 4 ms 524 KB Output is correct
4 Correct 4 ms 524 KB Output is correct
5 Correct 5 ms 524 KB Output is correct
6 Correct 4 ms 572 KB Output is correct
7 Correct 4 ms 572 KB Output is correct
8 Correct 3 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 4 ms 572 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 4 ms 772 KB Output is correct
15 Correct 5 ms 772 KB Output is correct
16 Correct 4 ms 772 KB Output is correct
17 Correct 5 ms 772 KB Output is correct
18 Correct 4 ms 772 KB Output is correct
19 Correct 4 ms 772 KB Output is correct
20 Correct 4 ms 772 KB Output is correct
21 Correct 939 ms 9040 KB Output is correct
22 Correct 799 ms 9064 KB Output is correct
23 Correct 797 ms 9208 KB Output is correct
24 Correct 869 ms 9208 KB Output is correct
25 Correct 934 ms 9244 KB Output is correct
26 Correct 782 ms 9244 KB Output is correct
27 Correct 889 ms 9244 KB Output is correct
28 Correct 869 ms 9244 KB Output is correct
29 Correct 936 ms 9244 KB Output is correct
30 Execution timed out 2061 ms 171152 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 171152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 508 KB Output is correct
3 Correct 4 ms 524 KB Output is correct
4 Correct 4 ms 524 KB Output is correct
5 Correct 5 ms 524 KB Output is correct
6 Correct 4 ms 572 KB Output is correct
7 Correct 4 ms 572 KB Output is correct
8 Correct 3 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 4 ms 572 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 4 ms 772 KB Output is correct
15 Correct 5 ms 772 KB Output is correct
16 Correct 4 ms 772 KB Output is correct
17 Correct 5 ms 772 KB Output is correct
18 Correct 4 ms 772 KB Output is correct
19 Correct 4 ms 772 KB Output is correct
20 Correct 4 ms 772 KB Output is correct
21 Correct 939 ms 9040 KB Output is correct
22 Correct 799 ms 9064 KB Output is correct
23 Correct 797 ms 9208 KB Output is correct
24 Correct 869 ms 9208 KB Output is correct
25 Correct 934 ms 9244 KB Output is correct
26 Correct 782 ms 9244 KB Output is correct
27 Correct 889 ms 9244 KB Output is correct
28 Correct 869 ms 9244 KB Output is correct
29 Correct 936 ms 9244 KB Output is correct
30 Execution timed out 2061 ms 171152 KB Time limit exceeded
31 Halted 0 ms 0 KB -