제출 #423529

#제출 시각아이디문제언어결과실행 시간메모리
423529patrikpavic2Financial Report (JOI21_financial)C++17
100 / 100
709 ms37972 KiB
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <set> #define PB push_back using namespace std; const int N = 3e5 + 500; const int OFF = (1 << 19); const int INF = 0x3f3f3f3f; int n, d, A[N], sm[N]; vector < int > saz, rv[N]; set < int > S; int T[2 * OFF], dp[N], sol; void update(int i, int x){ T[OFF + i] = max(T[OFF + i], x); for(i = (i + OFF) / 2 ; i ; i /= 2) T[i] = max(T[2 * i], T[2 * i + 1]); } int query(int i, int a, int b, int lo, int hi){ if(lo <= a && b <= hi) return T[i]; if(a > hi || b < lo) return 0; return max(query(2 * i, a, (a + b) / 2, lo, hi), query(2 * i + 1, (a + b) / 2 + 1, b, lo, hi)); } inline void remove(int l, int r){ for(auto it = S.lower_bound(l);it != S.end() && *it <= r;it = S.erase(it)); } int main(){ scanf("%d%d", &n, &d); for(int i = 0;i < n;i++){ scanf("%d", A + i); saz.PB(A[i]); S.insert(i); } sort(saz.begin(), saz.end()); saz.erase(unique(saz.begin(), saz.end()), saz.end()); for(int i = 0;i < n;i++){ A[i] = lower_bound(saz.begin(), saz.end(), A[i]) - saz.begin(); rv[A[i]].PB(i); } for(int i = 0;i < n;i++){ for(int j : rv[i]) remove(j - d + 1, j); for(int j : rv[i]){ sm[j] = ((int)S.size() == 0 || *S.begin() > j ? 0 : *(--S.lower_bound(j))); } } for(int i = 0;i < n;i++){ reverse(rv[i].begin(), rv[i].end()); for(int j : rv[i]){ dp[j] = query(1, 0, OFF - 1, sm[j], j) + 1; update(j, dp[j]); sol = max(sol, dp[j]); } } printf("%d\n", sol); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d", &n, &d);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
#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...