Submission #1073305

# Submission time Handle Problem Language Result Execution time Memory
1073305 2024-08-24T12:07:26 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
0 / 100
3000 ms 7248 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);
        }
        ans[i] = 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 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 3164 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3095 ms 7248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -