제출 #968057

#제출 시각아이디문제언어결과실행 시간메모리
968057vjudge1Vudu (COCI15_vudu)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; int n, fw[1000001] long long ans; void update(int idx, int val){ for(; idx <= n; idx+=(idx&-idx)) fw[idx]+=val; } long long query(int idx){ long long sum = 0; for(; idx; idx-=(idx&-idx)) sum+=fw[idx]; return sum; } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n; long long qs[n+1], k; vector<long long> v; memset(qs, 0, sizeof(qs)); for(int i = 1; i<=n; ++i) cin >> qs[i]; cin >> k; for(int i = 1; i<=n; ++i) qs[i]+=qs[i - 1]; for(int i = 1; i<=n; ++i) v.push_back(qs[i] - i*k); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end())); for(int i = 0; i<=n; ++i){ int id = lower_bound(v.begin(), v.end(), qs[i] - i*k) - v.begin(); ans+=query(id+1); update(id+1, 1); } cout << ans; }

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

vudu.cpp:6:1: error: expected initializer before 'long'
    6 | long long ans;
      | ^~~~
vudu.cpp: In function 'void update(int, int)':
vudu.cpp:9:38: error: 'fw' was not declared in this scope
    9 |     for(; idx <= n; idx+=(idx&-idx)) fw[idx]+=val;
      |                                      ^~
vudu.cpp: In function 'long long int query(int)':
vudu.cpp:14:38: error: 'fw' was not declared in this scope
   14 |     for(; idx; idx-=(idx&-idx)) sum+=fw[idx];
      |                                      ^~
vudu.cpp: In function 'int main()':
vudu.cpp:32:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   32 |         ans+=query(id+1);
      |         ^~~
      |         abs
vudu.cpp:35:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   35 |     cout << ans;
      |             ^~~
      |             abs