제출 #1193384

#제출 시각아이디문제언어결과실행 시간메모리
1193384yoshiArranging Shoes (IOI19_shoes)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ss second
#define ff first
using namespace std;
ll df[1234567],ans; 
vector<ll> vv[1234567];
struct segtree{
    ll n;
    vector<ll>d;
    segtree(ll n){
        d.resize(4*n);
        build(1,1,n);
    }
    void build(ll v, ll l, ll r){
        if(l == r){
            d[v] = 1;
            return;
        }
        ll m = (l+r)/2;
        build(v*2,l,m);
        build(v*2+1,m+1,r);
        d[v] = d[v*2]+d[v*2+1];
    }
    void update(ll v,ll l, ll r, ll pos, ll val){
        if(pos < l or pos > r)return;
        if(l == r){
            d[v] = val;
            return;
        }
        ll m = (l+r)/2;
        update(v*2,l,m,pos,val);
        update(v*2+1,m+1,r,pos,val);
        d[v] = d[v*2]+d[v*2+1];
    }
    ll query(ll v, ll l, ll r, ll L, ll R){
        if(R<L||R<l||r<L) return 0ll;
        if(L<=l&&r<=R) return d[v];
        ll m = (l+r)/2;
        return query(v*2,l,m,L,R) + query(v*2+1,m+1,r,L,R);
    }
};
int count_swaps(vector<int> a){
    int n=a.size()/2;
    vector<ll> s;
    s.pb(0);
    for(auto x: a) s.pb(x);
    map<ll,vector<ll>> w;
    for(i=1; i<=s.size(); i++){
        w[s[i]].pb(i);
    }
    segtree yo(2*n);
    ll c=0;
    ll cnt=0;
    vector<pair<ll,ll>> v;
    for(ll i=1 ; i<=100000; i++){
        for(j=0; j<w[i].size(); j++){
            if(w[-i][j] < w[i][j]){
                v[c].ff=w[-i][j]+1;
                v[c].ss=w[i][j]-1;
            }else{
                v[c].ff=w[-i][j]-1;
                v[c].ss=w[i][j]+1;
                cnt++;
            }
            c++;
        }
    }
    sort(v.begin(), v.end());
    for( i=0;i<c; i++){
        cnt+= yo.query(1 , 1 ,2*n , v[i].ff, v[i].ss);
        yo.update(1, 1, 2*n, v[i].ss+1 , 0);
    }
    return cnt;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:50:9: error: 'i' was not declared in this scope
   50 |     for(i=1; i<=s.size(); i++){
      |         ^
shoes.cpp:58:13: error: 'j' was not declared in this scope
   58 |         for(j=0; j<w[i].size(); j++){
      |             ^
shoes.cpp:71:10: error: 'i' was not declared in this scope
   71 |     for( i=0;i<c; i++){
      |          ^