Submission #90873

#TimeUsernameProblemLanguageResultExecution timeMemory
90873YottaByteTrading (IZhO13_trading)C++14
0 / 100
2045 ms4856 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define pb push_back #define mk make_pair #define fr first #define endl '\n' #define sc second #define pii pair < int, int > #define piii pair < int, pair < int, int > > const int N = 3e5 + 1; int n, m, c; int t[N * 4], h[N * 4]; vector < pair < pii, pii > > v; void push(int v, int l, int r) { if(h[v]) { t[v] = (r - l + 1) * h[v]; h[v + v] = h[v]; h[v + v + 1] = h[v]; h[v] = 0; } } void upd(int ql, int qr, int x, int v = 1, int l = 1, int r = n) { push(v, l, r); if(l > qr || r < ql) return; //cout << l << " " << r << endl; if(ql <= l && r <= qr) { h[v] = x; push(v, l, r); return; } else { int mid = l + r >> 1; upd(ql, qr, x, v + v, l, mid); upd(ql, qr, x, v + v + 1, mid + 1, r); } t[v] = t[v + v] + t[v + v + 1]; } long long getsum(int ql, int qr, int v = 1, int l = 1, int r = n) { push(v, l, r); if(l > qr || r < ql) return 0; if(ql <= l && r <= qr) return t[v]; int mid = l + r >> 1; return getsum(ql, qr, v + v, l, mid) + getsum(ql, qr, v + v + 1, mid + 1, r); } void solve(int l, int r, int x) { if(getsum(l, r) == 0) { //cout << l << " " << r << endl; upd(l, r, x); //puts(""); return; } if(l == r) { int id = getsum(l, l) - 1; int match = v[id].fr.fr + (l - v[id].sc.fr); int cur = v[x - 1].fr.fr + (l - v[x - 1].sc.fr); if(match < cur) { upd(l, l, x); } return; } int mid = l + r >> 1; solve(l, mid, x); solve(mid + 1, r, x); } int get(int x, int pos) { //cout << x << endl; if(x == 0) return 0; int res = v[x - 1].fr.fr; res += (pos - v[x - 1].sc.fr); return res; } main() { cin >> n >> m; c = m; for(int i = 1; i <= m; i++) { int l, r, x; cin >> l >> r >> x; v.pb( mk( mk( x, (r - l + 1) ), mk( l, r ) ) ); } sort(v.rbegin(), v.rend()); for(int i = 1; i <= m; i++) { int l = v[i - 1].sc.fr; int r = v[i - 1].sc.sc; solve(l, r, i); } //cout << getsum(1, 5) << endl; //return 0; for(int i = 1; i <= n; i++) { //cout << i << " "; //get(getsum(i, i), i); //puts(""); cout << get(getsum(i, i), i) << " "; } } /** 5 2 1 3 2 2 4 6 6 4 1 2 5 4 4 3 6 6 1 5 6 1 **/

Compilation message (stderr)

trading.cpp: In function 'void upd(int, int, int, int, int, int)':
trading.cpp:44:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
trading.cpp: In function 'long long int getsum(int, int, int, int, int)':
trading.cpp:59:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
trading.cpp: In function 'void solve(int, int, int)':
trading.cpp:87:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
trading.cpp: At global scope:
trading.cpp:104:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...