답안 #741940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741940 2023-05-15T06:18:42 Z vjudge1 Boat (APIO16_boat) C++17
0 / 100
2000 ms 319948 KB
// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")  
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int K = 800;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;

int n, sz;
int a[maxn];
int b[maxn];
int t[maxn];
int dp[maxn];
map<int, int>cnt;

int add(int a, int b){
    return (a+b)%mod;
}

void upd(int x, int y, int v=1, int tl=1, int tr=sz){
    if(tl == tr) t[v] = add(t[v], y);
    else{
        int tm = (tl+tr)>>1;
        if(x <= tm) upd(x, y, v<<1, tl, tm);
        else upd(x, y, (v<<1)+1, tm+1, tr);
        t[v] = add(t[v<<1], t[(v<<1)+1]);
    } 
}

int get(int r, int v=1, int tl=1, int tr=sz){
    if(r < tl) return 0;
    if(tr <= r) return t[v];
    int tm = (tl+tr)>>1;
    return add(get(r, v<<1, tl, tm), get(r, (v<<1)+1, tm+1, tr));
}

void IHTW(){
    cin >> n;
    int ans = 0;
    set<int>st;
    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i];
        for(int j=a[i]; j<=b[i]; j++) st.insert(j);
    }
    for(auto to: st) cnt[to] = ++sz;
    for(int i=1; i<=n; i++){
        for(int j=b[i]; j>=a[i]; j--){
            int nw = add(get(j-1), 1);
            upd(j, nw);
            ans = add(ans, nw);
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    while(t--) IHTW();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2069 ms 319948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -