Submission #1112328

#TimeUsernameProblemLanguageResultExecution timeMemory
1112328RequiemTeams (CEOI11_tea)C++17
100 / 100
564 ms125880 KiB
#include<bits/stdc++.h> //#define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "divteam" using namespace std; template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; /** Ta có thể dễ dàng tính được số team nhiều nhất bằng dp thông thường. Bây giờ ta cần kiểm soát kích thước của tập lớn nhất. Giả sử tập lớn nhất là mid. dp_i = dp_j + 1 (j thuộc [i - mid, i - a[i] ]. Ta nhận thấy rằng là i - mid sẽ tăng dần, trong khi i - a[j] sẽ giảm dần. Mình có thể dùng deque ko nhỉ. **/ const int MAXN = 1e6 + 1; vector<ii> query[MAXN]; vector<int> listPosition[MAXN]; int pos_ptr[MAXN]; int ord[MAXN], cnt[MAXN], newOrd[MAXN]; int n; int dp[MAXN], trace[MAXN], mx = 0; void fastscan(int &number){ //variable to indicate sign of input number bool negative = false; register int c; number = 0; // extract current character from buffer c = getchar(); if (c=='-') { // number is negative negative = true; // extract the next character from the buffer c = getchar(); } // Keep on extracting characters if they are integers // i.e ASCII Value lies from '0'(48) to '9' (57) for (; (c>47 && c<58); c=getchar()) number = number *10 + c - 48; // if scanned input has a negative sign, negate the // value of the input number if (negative) number *= -1; } int stk[MAXN], sz_stk = 0; int lab[MAXN]; inline int root(int u){ return (lab[u] < 0) ? u : lab[u] = root(lab[u]); } bool check(int mid){ memset(dp, -0x3f, sizeof(dp)); dp[0] = 0; memset(lab, -1, sizeof(lab)); FOR(i, 1, n){ if (i - ord[i] >= 0) query[i - ord[i]].pb({max(0, i - mid), i}); } sz_stk = 0; FOR(i, 0, n){ if (sz_stk == 0) stk[sz_stk++] = i; else{ while(sz_stk > 0 and dp[stk[ sz_stk - 1 ] ]< dp[i]){ lab[stk[sz_stk - 1]] = i; sz_stk--; } stk[sz_stk++] = i; } for(auto &p: query[i]){ dp[p.se] = dp[root(p.fi)] + 1; trace[p.se] = root(p.fi); } } FOR(i, 1, n){ if (i - ord[i] >= 0) query[i - ord[i]].pop_back(); } return dp[n] == mx; } void traced(int s){ while(true){ int tr = trace[s]; cout << s - tr << ' '; FOR(i, tr + 1, s){ cout << listPosition[ord[i]][pos_ptr[ord[i]] - 1] << ' '; pos_ptr[ord[i]]--; } cout << endl; if (tr == 0) return; s = trace[s]; } } main() { fast; if (fopen(TASKNAME".inp","r")){ freopen(TASKNAME".inp","r",stdin); freopen(TASKNAME".out","w",stdout); } cin >> n; int mxA = 0; FOR(i, 1, n){ cin >> ord[i]; listPosition[ord[i]].pb(i); pos_ptr[ord[i]]++; maximize(mxA, ord[i]); cnt[ord[i]]++; } FOR(i, 1, n){ cnt[i] += cnt[i - 1]; } FOR(i, 1, n){ newOrd[cnt[ord[i]]--] = ord[i]; } FOR(i, 1, n){ ord[i] = newOrd[i]; } check(n); mx = dp[n]; int l = mxA, r = n - 1, res = n; while(l <= r){ int mid = (l + r) >> 1; if (check(mid)){ res = mid; r = mid - 1; } else{ l = mid + 1; } } check(res); cout << mx << endl; traced(n); } /** Warning: Đọc sai đề??? Cận lmao Code imple thiếu case nào không. Limit. **/

Compilation message (stderr)

tea.cpp: In function 'void fastscan(int&)':
tea.cpp:47:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |     register int c;
      |                  ^
tea.cpp: At global scope:
tea.cpp:126:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  126 | main()
      | ^~~~
tea.cpp: In function 'int main()':
tea.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
tea.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen(TASKNAME".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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...