Submission #785468

# Submission time Handle Problem Language Result Execution time Memory
785468 2023-07-17T09:23:38 Z bachhoangxuan Employment (JOI16_employment) C++17
100 / 100
160 ms 15364 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=1e9+7;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=250000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;
namespace BIT{
    int bit[2*maxn],n;
    void init(int N){n=N;}
    int query(int x){
        int res=0;
        for(int i=x;i>=1;i-=(i&(-i))) res+=bit[i];
        return res;
    }
    void update(int x,int val){
        for(int i=x;i<=n;i+=(i&(-i))) bit[i]+=val;
    }
    void update_range(int l,int r,int val){
        update(l,val);update(r+1,-val);
    }
}
int n,m,a[maxn];
void solve(){
    cin >> n >> m;
    vector<int> com;
    for(int i=1;i<=n;i++) cin >> a[i],com.push_back(a[i]);
    vector<pii> p;
    for(int i=1;i<=m;i++){
        int t,c,d=-1;cin >> t >> c;
        if(t==2) cin >> d,com.push_back(d);
        p.push_back({c,d});
    }
    sort(com.begin(),com.end());
    com.erase(unique(com.begin(),com.end()),com.end());
    int sz=(int)com.size();BIT::init(sz+1);
    auto get = [&](int x){
        return lower_bound(com.begin(),com.end(),x)-com.begin()+1;
    };
    auto add = [&](int x,int y,int val){
        if(x>y) BIT::update_range(y+1,x,val);
    };
    for(int i=1;i<=n;i++){
        a[i]=get(a[i]);
        if(i>=2) add(a[i-1],a[i],1);
    }
    for(auto &[c,d]:p){
        if(d==-1) cout << BIT::query(c=get(c))+(a[n]>=c) << '\n';
        else{
            d=get(d);
            if(c>=2) add(a[c-1],a[c],-1);
            if(c<n) add(a[c],a[c+1],-1);
            a[c]=d;
            if(c>=2) add(a[c-1],a[c],1);
            if(c<n) add(a[c],a[c+1],1);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

Compilation message

employment.cpp: In function 'void solve()':
employment.cpp:91:39: warning: operation on 'c' may be undefined [-Wsequence-point]
   91 |         if(d==-1) cout << BIT::query(c=get(c))+(a[n]>=c) << '\n';
      |                                      ~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 472 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 9 ms 1492 KB Output is correct
5 Correct 18 ms 2556 KB Output is correct
6 Correct 27 ms 3584 KB Output is correct
7 Correct 44 ms 5408 KB Output is correct
8 Correct 54 ms 6588 KB Output is correct
9 Correct 92 ms 10416 KB Output is correct
10 Correct 89 ms 10048 KB Output is correct
11 Correct 118 ms 12148 KB Output is correct
12 Correct 138 ms 13512 KB Output is correct
13 Correct 137 ms 13568 KB Output is correct
14 Correct 120 ms 13244 KB Output is correct
15 Correct 121 ms 13316 KB Output is correct
16 Correct 131 ms 13684 KB Output is correct
17 Correct 124 ms 13652 KB Output is correct
18 Correct 123 ms 13720 KB Output is correct
19 Correct 130 ms 13636 KB Output is correct
20 Correct 137 ms 13808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 472 KB Output is correct
17 Correct 2 ms 544 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 9 ms 1492 KB Output is correct
20 Correct 18 ms 2556 KB Output is correct
21 Correct 27 ms 3584 KB Output is correct
22 Correct 44 ms 5408 KB Output is correct
23 Correct 54 ms 6588 KB Output is correct
24 Correct 92 ms 10416 KB Output is correct
25 Correct 89 ms 10048 KB Output is correct
26 Correct 118 ms 12148 KB Output is correct
27 Correct 138 ms 13512 KB Output is correct
28 Correct 137 ms 13568 KB Output is correct
29 Correct 120 ms 13244 KB Output is correct
30 Correct 121 ms 13316 KB Output is correct
31 Correct 131 ms 13684 KB Output is correct
32 Correct 124 ms 13652 KB Output is correct
33 Correct 123 ms 13720 KB Output is correct
34 Correct 130 ms 13636 KB Output is correct
35 Correct 137 ms 13808 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 11 ms 1620 KB Output is correct
40 Correct 19 ms 2636 KB Output is correct
41 Correct 36 ms 3920 KB Output is correct
42 Correct 55 ms 5556 KB Output is correct
43 Correct 67 ms 7200 KB Output is correct
44 Correct 122 ms 12732 KB Output is correct
45 Correct 99 ms 10440 KB Output is correct
46 Correct 110 ms 11616 KB Output is correct
47 Correct 144 ms 14840 KB Output is correct
48 Correct 152 ms 15076 KB Output is correct
49 Correct 148 ms 15012 KB Output is correct
50 Correct 150 ms 14900 KB Output is correct
51 Correct 160 ms 15364 KB Output is correct
52 Correct 144 ms 15316 KB Output is correct
53 Correct 148 ms 15280 KB Output is correct
54 Correct 160 ms 15224 KB Output is correct
55 Correct 152 ms 15316 KB Output is correct