제출 #494112

#제출 시각아이디문제언어결과실행 시간메모리
494112maksim1744사탕 분배 (IOI21_candies)C++17
3 / 100
5062 ms16840 KiB
/* author: Maksim1744 created: 07.12.2021 02:14:12 */ #include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; #define mp make_pair #define pb push_back #define eb emplace_back #define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) template<typename T> vector<T>& operator-- (vector<T> &v){for (auto& i : v) --i; return v;} template<typename T> vector<T>& operator++ (vector<T> &v){for (auto& i : v) ++i; return v;} template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;} template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;} template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;} template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second; return is;} template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U> p){os << p.first << ' ' << p.second; return os;} template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);} template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);} template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;} template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;} #ifdef HOME #define SHOW_COLORS #include "/mnt/c/Libs/tools/print.cpp" #else #define show(...) void(0) #define debugf(fun) fun #define debugv(var) var #define mclock void(0) #define shows void(0) #define debug if (false) #endif void test_case() {} struct Q { int l, r, v; }; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { int n = c.size(); vector<Q> que; for (int i = 0; i < v.size(); ++i) { que.pb({l[i], r[i], v[i]}); } que.insert(que.begin(), Q{0, n-1, (int)1e9+100}); que.insert(que.begin()+1, Q{0, n-1, -(int)1e9-100}); vector<int> ans(n); for (int i = 0; i < n; ++i) { vector<ll> cur = {0}; for (auto q : que) { if (i < q.l || q.r < i) continue; cur.pb(cur.back() + q.v); } int ind = cur.size() - 1; ll mx = cur.back(), mn = cur.back(); while (mx - mn < c[i]) { --ind; mx = max(mx, cur[ind]); mn = min(mn, cur[ind]); } assert(cur[ind] == mn || cur[ind] == mx); int ifr; ll val; if (cur[ind] == mx) { ifr = find(cur.begin() + ind, cur.end(), mn) - cur.begin(); val = 0; } else { ifr = find(cur.begin() + ind, cur.end(), mx) - cur.begin(); val = c[i]; } for (int i = ifr + 1; i < cur.size(); ++i) val += cur[i] - cur[i - 1]; ans[i] = val; } return ans; } #ifdef HOUSE int main() { int n; assert(1 == scanf("%d", &n)); std::vector<int> c(n); for(int i = 0; i < n; ++i) { assert(scanf("%d", &c[i]) == 1); } int q; assert(1 == scanf("%d", &q)); std::vector<int> l(q), r(q), v(q); for(int i = 0; i < q; ++i) { assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3); } std::vector<int> ans = distribute_candies(c, l, r, v); for(int i = 0; i < n; ++i) { if (i > 0) { printf(" "); } printf("%d", ans[i]); } printf("\n"); fclose(stdout); return 0; } #endif

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

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0; i < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
candies.cpp:90:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for (int i = ifr + 1; i < cur.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...