Submission #172708

#TimeUsernameProblemLanguageResultExecution timeMemory
172708khohkoEmployment (JOI16_employment)C++17
100 / 100
204 ms13888 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ARRS ((ll)(4e5+100)) #define fr first #define sc second #define pb push_back #define MX ((ll)(1e9+100)) #define MAX ((ll)(1e18+100)) int n,q; int a[ARRS]; int up[ARRS]; int type[ARRS]; pair<int, int> compress[ARRS]; int fw[2*ARRS]; int quer(int idx){ int pas=0; for(;idx;idx-=idx&-idx) pas+=fw[idx]; return pas; } void updt(int idx, int val){ for(;idx<ARRS;idx+=idx&-idx) fw[idx]+=val; } void update_quer(int i, int k){ if(i&&a[i-1]>a[i]){ updt(a[i]+1, k); updt(a[i-1]+1, -k); } } int main(){ scanf("%d %d", &n, &q); for(int i=0; i<n; i++){ scanf("%d", &a[i]); compress[i]={a[i],i}; } a[n]=0; compress[n]={a[n],n}; n++; for(int i=n; i<n+q; i++){ scanf("%d", &type[i]); if(type[i] == 1){//query scanf("%d", &a[i]); } else {//update scanf("%d %d", &up[i], &a[i]); up[i]--; } compress[i]={a[i],i}; } sort(compress, compress+n+q); ll c=1; for(int i=0; i<n+q; i++){ if(i&&compress[i].fr!=compress[i-1].fr) c++; a[compress[i].sc]=c; } for(int i=0; i<n; i++) update_quer(i, 1); for(int i=n; i<n+q; i++){ if(type[i] == 1){ printf("%d\n", quer(a[i])); } else { update_quer(up[i], -1); update_quer(up[i]+1, -1); a[up[i]]=a[i]; update_quer(up[i], 1); update_quer(up[i]+1, 1); } } }

Compilation message (stderr)

employment.cpp: In function 'int main()':
employment.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~~
employment.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
employment.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &type[i]);
   ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:50:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i]);
    ~~~~~^~~~~~~~~~~~~
employment.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &up[i], &a[i]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...