Submission #1007864

#TimeUsernameProblemLanguageResultExecution timeMemory
1007864devariaotaLasers (NOI19_lasers)C++17
100 / 100
202 ms46212 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define pb push_back #define pii pair<ll,ll> #define fi first #define sec second #define endl '\n' #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update> #define ordered_multiset tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> const ll MOD = 998244353; const ll N = 5e5 + 5; const ll INF = 1e18; vector<ll>vec[N]; int32_t main(){ cin.tie(0)->sync_with_stdio(0); int tc = 1; // cin >> tc; while(tc--){ ll n,q; cin >> n >> q; for(int i=1;i<=q;i++){ ll a; cin >> a; for(int j=1;j<=a;j++){ ll x; cin >> x; vec[i].pb(x); } } set<pii>interval; for(int i=1;i<=q;i++){ ll l = 1; vector<ll>suff(vec[i].size() + 5); for(int j=vec[i].size();j>=0;j--){ if(j == vec[i].size()-1) suff[j] = vec[i][j]; else suff[j] = suff[j+1] + vec[i][j]; } for(int j=0;j<vec[i].size();j++){ ll val = max(0LL, 2*vec[i][j] - (n-(j == vec[i].size()-1 ? 0 : suff[j+1])-l+1)); if(val > 0) interval.insert({l-val+vec[i][j], l+vec[i][j]-1}); l += vec[i][j]; } } if(interval.size() == 0){ cout << 0 << endl; continue; } ll last = -1, prev = -1, mx = 0, ans = 0; for(auto i : interval){ if(prev == -1) prev = i.fi; if(i.fi != prev){ ans += max(0LL, last - max(prev - 1,mx)); mx = max(mx, last); prev = i.fi; last = 0; } last = i.sec; } ans += max(0LL, last - max(prev - 1,mx)); cout << ans << endl; } } /* 1 2 3 4 5 6 7 8 9 10 11 */

Compilation message (stderr)

lasers.cpp: In function 'int32_t main()':
lasers.cpp:39:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(j == vec[i].size()-1) suff[j] = vec[i][j];
      |            ~~^~~~~~~~~~~~~~~~~~
lasers.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |       for(int j=0;j<vec[i].size();j++){
      |                   ~^~~~~~~~~~~~~~
lasers.cpp:43:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         ll val = max(0LL, 2*vec[i][j] - (n-(j == vec[i].size()-1 ? 0 : suff[j+1])-l+1));
      |                                             ~~^~~~~~~~~~~~~~~~~~
#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...