답안 #1076048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076048 2024-08-26T10:46:18 Z dosts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
17 / 100
546 ms 247380 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e7;
const int N = 5001;
struct Query {
    int l=0,r=0,k=0,id=0;
};
struct FT
{
    int n;
    vi bit;
    FT(int nn) {
        n = nn;
        bit.assign(n+1,0);
    }

    void put(int p,int v) {
        for(int i=p;i<=n;i+=i&-i) bit[i]=max(bit[i],v);
    }
    int get(int p) {
        int ans = 0;
        for (int i=p;i>0;i-=i&-i) ans=max(ans,bit[i]);
        return ans;
    }
};

void solve() { 
    int n,q;
    cin >> n >> q;
    vi a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    vector<Query> queries(q+1);
    for (int i=1;i<=q;i++) {
        Query& Q = queries[i];
        cin >> Q.l >> Q.r >> Q.k;
        Q.id = i;
    }
    vector<Query> rq[n+1];
    for (int i=1;i<=q;i++) {
        rq[queries[i].r].push_back(queries[i]);
    }
    vi ans(q+1);
    a[0] = inf;
    FT ft(n);
    vi st{0};
    for (int i=1;i<=n;i++) {
        while (a[st.back()] <= a[i]) st.pop_back();
        if (st.back()) ft.put(n-st.back()+1,a[i]+a[st.back()]);
        for (auto Q : rq[i]){
            ans[Q.id] = ft.get(n-Q.l+1);
        }
        st.push_back(i);
    }
    for (int i=1;i<=q;i++) cout << (ans[i]<=queries[i].k) << '\n';
}
 
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 680 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 680 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 546 ms 247380 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 12632 KB Output is correct
2 Correct 44 ms 12880 KB Output is correct
3 Correct 37 ms 12628 KB Output is correct
4 Correct 43 ms 12752 KB Output is correct
5 Correct 39 ms 12628 KB Output is correct
6 Correct 31 ms 12760 KB Output is correct
7 Correct 37 ms 12784 KB Output is correct
8 Correct 52 ms 12224 KB Output is correct
9 Correct 37 ms 8384 KB Output is correct
10 Correct 44 ms 12432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 680 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 680 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -