제출 #90914

#제출 시각아이디문제언어결과실행 시간메모리
90914YottaByte거래 (IZhO13_trading)C++14
0 / 100
2067 ms3840 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; int t[N * 4], h[N * 4]; vector < piii > v; inline void push(int l, int r, int v) { if(h[v] == 0) return; t[v] = (r - l + 1) * h[v]; h[v + v] = h[v]; h[v + 1 + v] = h[v]; h[v] = 0; } inline void upd(int ql, int qr, int x, int v = 1, int l = 1, int r = n) { push(l, r, v); if(l > qr || r < ql) return; if(ql <= l && r <= qr) { h[v] = x; push(l, r, v); 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]; } inline int check(int ql, int qr, int v = 1, int l = 1, int r = n) { if(l > qr || r < ql); else { push(l, r, v); if(ql <= l && r <= qr) { if(t[v]) return 1; } else { int mid = l + r >> 1; return check(ql, qr, v + v, l, mid) + check(ql, qr, v + v + 1, mid + 1, r); } } return 0; } inline int getsum(int ql, int qr, int v = 1, int l = 1, int r = n) { if(l > qr || r < ql); else { push(l, r, v); if(ql <= l && r <= qr) { return t[v]; } else { int mid = l + r >> 1; return getsum(ql, qr, v + v, l, mid) + getsum(ql, qr, v + v + 1, mid + 1, r); } } return 0; } void solve(int l, int r, int x) { if(check(l, r) == 0) { upd(l, r, x); } if(l == r) return; int m = l + r >> 1; solve(l, m, x); solve(m + 1, r, x); } bool cmp( piii a, piii b ) { if( a.sc.fr - a.fr < b.sc.fr - b.fr ) { return true; } else if(a.fr == b.fr) { if(a.sc.fr < b.sc.fr) { return true; } else { return false; } } else { return false; } } main() { scanf("%d%d", &n, &m); for(int i = 1; i <= m; i++) { int l, r, x; scanf("%d%d%d", &l, &r, &x); v.pb(mk( x, mk( l, r ) )); } sort(v.begin(), v.end(), &cmp); //int cnt = 1; //for(auto i : v) //{ //printf("%d %d %d %d\n", cnt++, i.sc.fr, i.sc.sc, i.fr); //} for(int i = 1; i <= m; i++) { int l = v[i - 1].sc.fr; int r = v[i - 1].sc.sc; int x = v[i - 1].fr; solve(l, r, i); } for(int i = 1; i <= n; i++) { int id = getsum(i, i) - 1; if(id >= 0) printf("%d ", v[id].fr + i - v[id].sc.fr); else printf("0 "); } } /** 5 2 2 4 6 1 3 2 2 6 7 8 0 ---------------------- 6 4 1 2 5 4 4 3 5 6 1 6 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 **/

컴파일 시 표준 에러 (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 'int check(int, int, int, int, int)':
trading.cpp:63:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int mid = l + r >> 1;
              ~~^~~
trading.cpp: In function 'int getsum(int, int, int, int, int)':
trading.cpp:82:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int mid = l + r >> 1;
              ~~^~~
trading.cpp: In function 'void solve(int, int, int)':
trading.cpp:99:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = l + r >> 1;
          ~~^~~
trading.cpp: At global scope:
trading.cpp:127:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
trading.cpp: In function 'int main()':
trading.cpp:150:7: warning: unused variable 'x' [-Wunused-variable]
   int x = v[i - 1].fr;
       ^
trading.cpp:129: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:134: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...