Submission #61181

# Submission time Handle Problem Language Result Execution time Memory
61181 2018-07-25T10:02:34 Z Flugan42 Boat (APIO16_boat) C++14
9 / 100
2000 ms 171008 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 (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;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 5 ms 564 KB Output is correct
4 Correct 4 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 5 ms 680 KB Output is correct
11 Correct 4 ms 680 KB Output is correct
12 Correct 4 ms 680 KB Output is correct
13 Correct 3 ms 680 KB Output is correct
14 Correct 3 ms 680 KB Output is correct
15 Correct 4 ms 680 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 4 ms 748 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 5 ms 564 KB Output is correct
4 Correct 4 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 5 ms 680 KB Output is correct
11 Correct 4 ms 680 KB Output is correct
12 Correct 4 ms 680 KB Output is correct
13 Correct 3 ms 680 KB Output is correct
14 Correct 3 ms 680 KB Output is correct
15 Correct 4 ms 680 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 4 ms 748 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 896 ms 9056 KB Output is correct
22 Correct 907 ms 9056 KB Output is correct
23 Correct 793 ms 9056 KB Output is correct
24 Correct 815 ms 9056 KB Output is correct
25 Correct 898 ms 9056 KB Output is correct
26 Correct 965 ms 9096 KB Output is correct
27 Correct 903 ms 9124 KB Output is correct
28 Correct 826 ms 9124 KB Output is correct
29 Correct 964 ms 9124 KB Output is correct
30 Execution timed out 2067 ms 171008 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 171008 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 5 ms 564 KB Output is correct
4 Correct 4 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 5 ms 680 KB Output is correct
11 Correct 4 ms 680 KB Output is correct
12 Correct 4 ms 680 KB Output is correct
13 Correct 3 ms 680 KB Output is correct
14 Correct 3 ms 680 KB Output is correct
15 Correct 4 ms 680 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 4 ms 748 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 896 ms 9056 KB Output is correct
22 Correct 907 ms 9056 KB Output is correct
23 Correct 793 ms 9056 KB Output is correct
24 Correct 815 ms 9056 KB Output is correct
25 Correct 898 ms 9056 KB Output is correct
26 Correct 965 ms 9096 KB Output is correct
27 Correct 903 ms 9124 KB Output is correct
28 Correct 826 ms 9124 KB Output is correct
29 Correct 964 ms 9124 KB Output is correct
30 Execution timed out 2067 ms 171008 KB Time limit exceeded
31 Halted 0 ms 0 KB -