Submission #581037

#TimeUsernameProblemLanguageResultExecution timeMemory
581037AngusWongSnowball (JOI21_ho_t2)C++17
100 / 100
230 ms8500 KiB
#include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define f first #define s second using namespace std; ll n, q, x, a[200001], p=0, now=0, mxl=0, mxr=0, ans[200001]; vector<pll> v; int main() { cin >> n >> q; for (int i=1; i<=n; i++) cin >> a[i]; sort(a+1, a+n+1); for (int i=1; i<n; i++) v.push_back({a[i+1]-a[i], i}); sort(v.begin(), v.end()); while (q--){ cin >> x; now+=x; if (now<mxl){ mxl=now; while (p<v.size() && v[p].f<=mxr-mxl){ ans[v[p].s]+=mxr; ans[v[p].s+1]+=v[p].f-mxr; p++; } } if (now>mxr){ mxr=now; while (p<v.size() && v[p].f<=mxr-mxl){ ans[v[p].s]+=v[p].f+mxl; ans[v[p].s+1]-=mxl; p++; } } } while (p<v.size()){ ans[v[p].s]+=mxr; ans[v[p].s+1]-=mxl; p++; } ans[1]-=mxl, ans[n]+=mxr; for (int i=1; i<=n; i++) cout << ans[i] << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:22:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |             while (p<v.size() && v[p].f<=mxr-mxl){
      |                    ~^~~~~~~~~
Main.cpp:30:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             while (p<v.size() && v[p].f<=mxr-mxl){
      |                    ~^~~~~~~~~
Main.cpp:37:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (p<v.size()){
      |            ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...