제출 #388555

#제출 시각아이디문제언어결과실행 시간메모리
388555talant117408Boat (APIO16_boat)C++17
31 / 100
1058 ms135296 KiB
/* Code written by Talant I.D. */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; const int mod = 1e9+7; ll mode(ll a) { a %= mod; if (a < 0) a += mod; return a; } ll subt(ll a, ll b) { return mode(mode(a)-mode(b)); } ll add(ll a, ll b) { return mode(mode(a)+mode(b)); } ll mult(ll a, ll b) { return mode(mode(a)*mode(b)); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b&1) res = mult(res, a); a = mult(a, a); b >>= 1; } return res; } const int N = 503; int a[N], b[N], n; bool subtask1() { int flag = 0; for (int i = 1; i <= n; i++) { if (a[i] == b[i]) flag++; } return flag == n; } bool subtask2() { ll sum = 0; for (int i = 1; i <= n; i++) { sum += b[i]-a[i]; } return sum <= 1e6; } struct node { ll val; int lson, rson; node() { val = 0; lson = rson = -1; } } tree[8000007]; int vertices = 1; void create_lson(int v) { if (tree[v].lson == -1) { tree[v].lson = ++vertices; } } void create_rson(int v) { if (tree[v].rson == -1) { tree[v].rson = ++vertices; } } void update(int v, int l, int r, int pos, ll val) { if (l == r) { tree[v].val = add(tree[v].val, val); return; } int mid = (l+r) >> 1; create_lson(v); create_rson(v); if (pos <= mid) update(tree[v].lson, l, mid, pos, val); else update(tree[v].rson, mid+1, r, pos, val); tree[v].val = add(tree[tree[v].lson].val, tree[tree[v].rson].val); } ll get(int v, int l, int r, int ql, int qr) { if (l > qr || ql > r) return 0; if (ql <= l && r <= qr) return tree[v].val; int mid = (l+r) >> 1; create_lson(v); create_rson(v); return add(get(tree[v].lson, l, mid, ql, qr), get(tree[v].rson, mid+1, r, ql, qr)); } int main() { do_not_disturb cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } if (subtask1()) { vector <ll> dp(n+1); dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = i-1; j >= 0; j--) { if (a[i] > a[j]) { dp[i] = add(dp[i], dp[j]); } } } ll ans = 0; for (int i = 1; i <= n; i++) { ans = add(ans, dp[i]); } cout << ans << endl; return 0; } else if (subtask2()) { vector <vector <ll>> dp(n+1); dp[0].pb(1); update(1, 0, 1e9, 0, 1); ll ans = 0; for (int i = 1; i <= n; i++) { for (int j = a[i]; j <= b[i]; j++) { dp[i].pb(get(1, 0, 1e9, 0, j-1)); } for (int j = a[i]; j <= b[i]; j++) { update(1, 0, 1e9, j, dp[i][j-a[i]]); } } for (int i = 1; i <= n; i++) { for (auto to : dp[i]) ans = add(ans, to); } cout << ans << endl; return 0; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...