Submission #90901

#TimeUsernameProblemLanguageResultExecution timeMemory
90901YottaByteTrading (IZhO13_trading)C++14
0 / 100
2053 ms4916 KiB
#include <algorithm> #include <stdlib.h> #include <stdio.h> #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) { //printf("%d %d\n", l, r); //printf("idr = %d, idl = %d, curr = %d, curl = %d\n", idr + 1, idl + 1, curr, curl); if(getsum(l, r) == 0) { upd(l, r, x); //puts(""); return; } if(l == r) { return; } int mid = l + r >> 1; solve(l, mid, x); solve(mid + 1, r, x); } int get(int x, int pos) { if(x == 0) return 0; int res = v[x - 1].fr.sc; res += (pos - v[x - 1].sc.fr); return res; } main() { scanf("%d%d", &n, &m); c = m; for(int i = 1; i <= m; i++) { int l, r, x; scanf("%d%d%d", &l, &r, &x); v.pb( mk( mk ( x - l, x ), 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); } for(int i = 1; i <= n; i++) { printf("%d ", get(getsum(i, i), i)); } } /** 5 2 1 3 2 2 4 6 2 6 7 8 0 ---------------------- 6 4 1 2 5 4 4 3 6 6 1 5 6 1 5 6 0 3 1 2 ---------------------- 10 9 7 8 9 10 10 8 9 10 8 10 10 4 6 8 4 3 9 4 4 9 3 1 3 3 4 8 2 3 4 5 5 6 7 9 10 10 9 ---------------------- 3 4 2 2 4 1 1 4 3 3 1 1 3 0 4 4 2 **/

Compilation message (stderr)

trading.cpp: In function 'void upd(int, int, int, int, int, int)':
trading.cpp:47: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:62:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
trading.cpp: In function 'void solve(int, int, int)':
trading.cpp:85:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
trading.cpp: At global scope:
trading.cpp:100:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
trading.cpp: In function 'int main()':
trading.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
trading.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l, &r, &x);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...