제출 #681286

#제출 시각아이디문제언어결과실행 시간메모리
681286whqkrtk04Arranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms344 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; #define fi first #define se second const int INF = 1e9+1; const int P = 1000000007; const ll LLINF = (ll)1e18+1; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; } template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; } class segtree { private: int n; vector<int> seg; void update(int i, int s, int e, int j, int x) { if(j >= e || s > j) return; if(s+1 == e) seg[i] += x; else { update(i<<1, s, s+e>>1, j, x); update(i<<1|1, s+e>>1, e, j, x); seg[i] = seg[i<<1]+seg[i<<1|1]; } } int query(int i, int s, int e, int l, int r) { if(e <= l || r <= s) return 0; if(l <= s && e <= r) return seg[i]; return query(i<<1, s, s+e>>1, l, r)+query(i<<1|1, s+e>>1, e, l, r); } public: segtree(int n) { this->n = n; seg.resize(4*n); } void update(int j) { update(1, 0, n, j, 1); } int query(int j) { return query(1, 0, n, j, n); } }; ll count_swaps(vector<int> s) { vector<int> chk(s.size(), -1); for(int i = 0, cnt = 0; i < s.size(); i++) { int idx = abs(s[i])-1; if(chk[idx] >= 0) { pii tmp = (s[i] < 0 ? pii(i, chk[idx]) : pii(chk[idx], i)); s[tmp.fi] = cnt*2; s[tmp.se] = cnt*2+1; cnt++; } else chk[idx] = i; } //cout << s; segtree S(s.size()); ll ans = 0LL; for(int i = 0; i < s.size(); i++) { ans += S.query(s[i]); S.update(s[i]); } return ans; }

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

shoes.cpp: In member function 'void segtree::update(int, int, int, int, int)':
shoes.cpp:27:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |    update(i<<1, s, s+e>>1, j, x);
      |                    ~^~
shoes.cpp:28:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |    update(i<<1|1, s+e>>1, e, j, x);
      |                   ~^~
shoes.cpp: In member function 'int segtree::query(int, int, int, int, int)':
shoes.cpp:35:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   return query(i<<1, s, s+e>>1, l, r)+query(i<<1|1, s+e>>1, e, l, r);
      |                         ~^~
shoes.cpp:35:54: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   return query(i<<1, s, s+e>>1, l, r)+query(i<<1|1, s+e>>1, e, l, r);
      |                                                     ~^~
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:48:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0, cnt = 0; i < s.size(); i++) {
      |                          ~~^~~~~~~~~~
shoes.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i = 0; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...