제출 #90916

#제출 시각아이디문제언어결과실행 시간메모리
90916YottaByte거래 (IZhO13_trading)C++14
0 / 100
2044 ms3784 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, a[N]; int u[N * 4]; vector < piii > v; inline void upd(int ql, int qr, int x, int v = 1, int l = 1, int r = n) { if(u[v] == r - l + 1) return; if(l > qr || r < ql) return; if(l == r && !u[v]) { a[l] = x; u[v] = 1; 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); } u[v] = u[v + v] + u[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 { if(ql <= l && r <= qr) { if(u[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; } 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); c = 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 = a[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:35: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:53:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int mid = l + r >> 1;
              ~~^~~
trading.cpp: In function 'void solve(int, int, int)':
trading.cpp:70:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = l + r >> 1;
          ~~^~~
trading.cpp: At global scope:
trading.cpp:98:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
trading.cpp: In function 'int main()':
trading.cpp:122:7: warning: unused variable 'x' [-Wunused-variable]
   int x = v[i - 1].fr;
       ^
trading.cpp:100: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:106: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...