이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nx = 4e5+100;
int st[nx], co[nx], lz[nx];
void cons(int i, int l, int r){
    st[i]=lz[i]=0;
    co[i] = r-l+1;
    if(l==r) return;
    int m = l+r>>1;
    cons(i<<1, l, m);cons(i<<1|1, m+1, r);
}
void upd(int i, int l, int r, int a, int b, int v){
    if(lz[i]){
        st[i] += lz[i];
        if(l!=r){
            lz[i<<1] += lz[i];
            lz[i<<1|1] += lz[i];
        }
        lz[i]=0;
    }
    if(b<l||r<a) return;
    if(a <= l && r <= b) {
        st[i] += v;
        if(l!=r){
            lz[i<<1] += v;
            lz[i<<1|1] += v;
        }
        return;
    }
    int m = l+r>>1;
    upd(i<<1, l, m, a, b, v);upd(i<<1|1, m+1, r, a, b, v);
    st[i] = max(st[i<<1], st[i<<1|1]);
    co[i] = 0;
    if(st[i<<1] == st[i]) co[i]=co[i<<1];
    if(st[i<<1|1] == st[i]) co[i]+=co[i<<1|1];
}
void ans(int n, int k, int a[], int b[]){
    cons(1, 0, n-1);
    for(int i = 0;i < k;i++) {
        upd(1, 0, n-1, max(0, b[a[i]]-k+1), min(n-k,b[a[i]]), 1);
    }
    int tans = st[1];long long c = co[1];
    for(int i = 1;i+k <= n;i++){
        upd(1, 0, n-1, max(0, b[a[i-1]]-k+1), min(n-k,b[a[i-1]]), -1);
        upd(1, 0, n-1, max(0, b[a[i+k-1]]-k+1), min(n-k,b[a[i+k-1]]), 1);
        if(st[1] > tans){
            tans = st[1];
            c = co[1];
        } else if(st[1] == tans) c += co[1];
    }
    cout << tans << ' ' << c << '\n';
}
void solve(){
    int n, k ,q;cin >> n >> k >> q;
    int a[n],b[n+1];
    for(int i = 0;i < n;i++) cin >> a[i];
    for(int i = 0;i < n;i++) {
        int th;cin >> th;
        b[th] = i;
    }
    ans(n, k, a, b);
    while(q--){
        int p;cin >> p;
        p--;
        swap(a[p],a[p+1]);
        ans(n,k,a,b);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void cons(int, int, int)':
Main.cpp:9:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    9 |     int m = l+r>>1;
      |             ~^~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:30:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |     int m = l+r>>1;
      |             ~^~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |