제출 #1263986

#제출 시각아이디문제언어결과실행 시간메모리
1263986herominhsteveVolontiranje (COCI21_volontiranje)C++20
0 / 110
0 ms324 KiB
#include <bits/stdc++.h> #define el '\n' #define FNAME "NAME" #define allof(x) x.begin(),x.end() #define allof1(x) x.begin()+1,x.end() #define mset(x,n) memset(x,(n),sizeof(x)) using namespace std; const long long MOD = (long long) 1e9+7; template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;} template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;} void setup(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if (fopen(FNAME".inp","r")){ freopen(FNAME".inp","r",stdin); freopen(FNAME".out","w",stdout); } } template<typename T> struct FenwickTree{ int n; vector<T> bit; FenwickTree(int N=0){ n=N; if (n>0){ bit.resize(n+1,0); } } void update(int node,T val){ while (node<=n){ maximize(bit[node],val); node += (node & -node); } } T getVal(int node){ T res=0; while (node>0){ maximize(res,bit[node]); node -= (node & -node); } return res; } }; FenwickTree<int> bit; int n; vector<int> a; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void gen(){ cout<<n<<el; vector<int> b(allof(a)); shuffle(allof(b),rng); for (int x:b) cout<<x<<" "; } void init(){ cin>>n; a.resize(n); for (int &x:a) cin>>x; bit = FenwickTree<int>(n); // gen(); } void sol(){ vector<int> dp(n,0); for (int i=0;i<n;i++){ dp[i] = bit.getVal(a[i]-1) + 1; bit.update(a[i],dp[i]); } int maxLen = bit.getVal(n); vector<int> id; for (int i=0;i<n;i++) if (dp[i]==maxLen) id.push_back(i); // cerr<<maxLen<<el; vector<vector<int>> res; vector<bool> visited(n,0); while (!id.empty()){ int curLen = maxLen; int big = id.back(); id.pop_back(); int curMax = a[big]+1; vector<int> path; for (int i=big;i>=0 and curLen>0;i--){ if (a[i] < curMax and dp[i]==curLen and !visited[i]){ path.push_back(i); curLen--; curMax = a[i]; visited[i] = 1; } } reverse(allof(path)); res.push_back(path); } reverse(allof(res)); cout<<res.size()<<" "<<maxLen<<el; for (vector<int> v : res){ for (int x : v) cout<<x+1<<" "; cout<<el; } } int main(){ setup(); init(); sol(); }

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

Main.cpp: In function 'void setup()':
Main.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |                 freopen(FNAME".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 freopen(FNAME".out","w",stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...