답안 #989935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989935 2024-05-29T06:02:04 Z kasdo Poklon (COCI17_poklon) C++14
140 / 140
4566 ms 29300 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("popcnt")
#define int long long
#define ll long long
#define endl '\n'
#define debug(...) printf(__VA_ARGS__)
//#define debug(...)
#define trace(x) cout<<#x<<"="<<x<<endl;
//#define trace(x)
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define umap unordered_map
#define uset unordered_set
#define mk make_pair
#define pb push_back
#define pob pop_back
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define read(x) for (auto& zu: (x)) cin >> zu;
#define F first
#define S second
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define mustawa ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define pii pair<int,int>
#define mishari main
const int inf=1e9+7;
void fa(bool ok){ cout << (ok ? "YES": "NO") << endl;}
int pw(ll a,ll b,ll mod=1e9+7){
    ll result = 1;
    while(b) {
        if(b&1) {
            result = (result*a)%mod;
        }
        a = (a * a) % mod;
        b>>=1;
    }
    return result;
}
inline void usaco(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}vi pows(19,1);
int check(int x){
    int d = 0;
    while(x){
        x >>= 1;
        d += x;
    }return d;
}
struct query{
    int l,r,inx;
};int n,sqr,qu;
int sub=0;
bool compare(query a,query b){
    return mk(a.l/sqr, a.r) < mk(b.l/sqr, b.r);
}umap<int,int>frq;
void add(int val) {
    if(frq[val]==1)sub++;
    if(frq[val]==2)sub--;
    frq[val]++;
}

void remove(int val) {
    if(frq[val]==2)sub--;
    if(frq[val]==3)sub++;
    frq[val]--;
}
void solve() {
    cin>>n>>qu;
    sqr=sqrt(n);
    vi v(n);
    read(v);
    vector<query>q(qu);
    for(int i=0;i<qu;i++){
        int l,r;
        cin>>l>>r;
        l--,r--;
        q[i]={l,r,i};
    }sort(all(q), compare);
    int L=0,R=-1;
    vi ans(qu);
    for(auto [l,r,ind]:q){
        while(R>r){
            remove(v[R]);R--;
        }while(R<r){
            R++;
            add(v[R]);
        }while(L<l){
            remove(v[L]);
            L++;
        }while(L>l){
            L--;
            add(v[L]);
        }ans[ind]=sub;
    }for(auto i:ans)cout<<i<<endl;
}
signed mishari(){
    mustawa;
    //usaco("a");
    int t = 1;
    //cin>>t;
    for(int i=1;i<=t;i++){
        //cout<<"Case "<<i<<":"<<endl;
        solve();
    }
}

Compilation message

poklon.cpp: In function 'void solve()':
poklon.cpp:88:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |     for(auto [l,r,ind]:q){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 7 ms 724 KB Output is correct
5 Correct 416 ms 5796 KB Output is correct
6 Correct 421 ms 5804 KB Output is correct
7 Correct 1220 ms 11808 KB Output is correct
8 Correct 2321 ms 17772 KB Output is correct
9 Correct 3280 ms 23656 KB Output is correct
10 Correct 4566 ms 29300 KB Output is correct