Submission #1073302

# Submission time Handle Problem Language Result Execution time Memory
1073302 2024-08-24T12:05:43 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
0 / 100
3000 ms 6480 KB
#include <bits/stdc++.h>
using namespace std;

#define STALIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define pb push_back
#define pf push_front
#define nl "\n"
#define ll long long
#define int long long
#define all(v) (v).begin() + 1, (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
#define len(a) a.size()
#define pii pair<int,int>
const int N = 1e5 + 6;
const ll md = 998244353;
const ll mod = 1e9 + 7;
const ll mega = 1e6 + 3;
const int inf = 1e9;
struct niga{
    int l , r , k , id;
};
int a[N];
set<int>st;
map<int , int>mp;
void add(int l){
    st.insert(a[l]);
    mp[a[l]]--;
}
void del(int l){
    mp[a[l]]--;
    if(mp[a[l]] == 0)st.erase(a[l]);
}
bool cmp(niga a , niga b){
    if(a.l / 200 == b.l / 200){
        return a.r < b.r;
    }
    return a.l / 200 < b.l / 200; 
}
void CCCP() {
    int n , m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)cin >> a[i];
    vector<niga>vec(m + 1);
    for(int i = 1; i <= m; ++i){
        cin >> vec[i].l >> vec[i].r >> vec[i].k;
        vec[i].id = i;
    }
    sort(all(vec) , cmp);
    int l = 1 , r = 0;
    vector<int>ans(m + 1);
    for(int i = 1; i <= m; ++i) {
        while (r < vec[i].r) {
          ++ r;
          add(r);
        }
        while (r > vec[i].r) {
          del(r);
          -- r;
        }
        while (l < vec[i].l) {
          del(l);
          ++ l;
        }
        while (l > vec[i].l) {
          -- l;
          add(l);
        }
        auto to1 = *st.begin();
        auto to2 = *st.rbegin();
        // cout << to1 << " " << to2 << nl;
        if(to1 + to2 <= vec[i].k)ans[vec[i].id] = 1;
        else ans[vec[i].id] = 0;
    }
    for(int i = 1; i <= m; ++i) cout << ans[i] << "\n";
}

signed main() {
    STALIN;
    int t = 1;
    // cin >> t;
    while (t--) {
        CCCP();
    }
    #ifndef ONLINE_JUDGE
    cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 2136 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3012 ms 6480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -