제출 #157210

#제출 시각아이디문제언어결과실행 시간메모리
157210abilArranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() //#define int long long using namespace std; const int N = (1e5 + 12); const int mod = (1e9 + 7); const int INF = (0x3f3f3f3f); int a[N], minus[N], used[N], t[N * 4]; set<int > s[2][N]; set<int > :: iterator it; int n; void update(int pos, int new_val, int v = 1,int tl = 1,int tr = n){ if(tl == tr){ t[v] = new_val; } else{ int mid = (tl + tr) >> 1; if(mid >= pos){ update(pos, new_val, v + v, tl, mid); } else{ update(pos, new_val, v + v + 1, mid + 1, tr); } t[v] = t[v + v] + t[v + v + 1]; } } int get(int l,int r, int v = 1,int tl = 1,int tr = n){ if(tl > r || tr < l){ return 0; } if(l <= tl && r >= tr){ return t[v]; } int mid = (tl + tr) >> 1; return (get(l, r, v + v, tl, mid) + get(l, r, v + v + 1, mid + 1, tr)); } main() { cin >> n; for(int i = 1;i <= n; i++){ scanf("%d", &a[i]); if(a[i] < 0){ s[0][abs(a[i])].insert(i); } else{ s[1][a[i]].insert(i); } } long long ans = 0, plus = 0; for(int i = 1;i <= n; i++){ if(used[i]){ continue; } if(a[i] < 0){ it = s[1][abs(a[i])].begin(); s[1][abs(a[i])].erase(s[1][abs(a[i])].begin()); s[0][abs(a[i])].erase(s[0][abs(a[i])].begin()); ans += *it - i - 1; ans -= get(i, *it); update(i, -1); update(*it, 1); used[*it] = 1; } else{ it = s[0][a[i]].begin(); s[0][a[i]].erase(s[0][a[i]].begin()); s[1][abs(a[i])].erase(s[1][abs(a[i])].begin()); ans += *it - i; ans -= get(i, i); update(i, -1); update(*it, 1); used[*it] = 1; } } cout << ans; } /* 6 -2 2 -2 2 -2 2 */

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

shoes.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
shoes.cpp: In function 'int main()':
shoes.cpp:59:21: warning: unused variable 'plus' [-Wunused-variable]
  long long ans = 0, plus = 0;
                     ^~~~
shoes.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
/tmp/cctNJqEh.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccj87P51.o:shoes.cpp:(.text.startup+0x0): first defined here
/tmp/cctNJqEh.o: In function `main':
grader.cpp:(.text.startup+0x272): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status