제출 #1124390

#제출 시각아이디문제언어결과실행 시간메모리
1124390CadocFinancial Report (JOI21_financial)C++17
100 / 100
472 ms25680 KiB
#include<bits/stdc++.h> using namespace std; #define el cout << '\n' #define ll long long #define pii pair<int, int> #define fi first #define se second #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define INF 0x3f3f3f3f #define LINF 0x3f3f3f3f3f3f3f3f #define MOD 1000000007 #define N 300005 int n, d; int a[N]; int par[N], sz[N], l[N]; int dp[N], st[N << 2]; // dp(i) la day con tang dai nhat ket thuc tai i // dp(i) = dp(j) + 1 (j den duoc i) bool cmp(int i, int j){ return pii(a[i], -i) < pii(a[j], -j); } int get(int u){ return par[u] = (u == par[u]? u:get(par[u])); } int join(int u, int v){ u = get(u), v = get(v); if(u == v) return 0; if(sz[u] < sz[v]) swap(u, v); sz[u] += sz[v]; par[v] = u; l[u] = min(l[u], l[v]); return 1; } void upd(int id, int l, int r, int i, int x){ if(i < l || r < i) return; if(l == r) return st[id] = x, void(); int m = (l+r)>>1; upd(id<<1, l, m, i, x); upd(id<<1|1, m+1, r, i, x); st[id] = max(st[id<<1], st[id<<1|1]); } int get(int id, int l, int r, int u, int v){ if(v < l || r < u) return 0; if(u <= l && r <= v) return st[id]; int m = (l+r)>>1; return max(get(id<<1, l, m, u, v), get(id<<1|1, m+1, r, u, v)); } void Solve(){ cin >> n >> d; for(int i=1; i<=n; ++i) cin >> a[i]; vector<int> vec; for(int i=1; i<=n; ++i) vec.eb(i); sort(all(vec), cmp); for(int i=1; i<=n; ++i){ par[i] = i; l[i] = max(1, i - d); sz[i] = 1; } int Ans = 1; set<int> s; for(int i:vec){ set<int>::iterator it = s.lower_bound(i); if(it != s.end()){ if(*it - i <= d) join(i, *it); } if(it != s.begin()){ it--; if(i - *it <= d) join(i, *it); } int u = get(i); dp[i] = get(1, 1, n, l[u], i) + 1; upd(1, 1, n, i, dp[i]); Ans = max(Ans, dp[i]); s.insert(i); } cout << Ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define NAME "TASK" if(fopen(NAME".inp", "r")){ freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } Solve(); return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...