제출 #1286042

#제출 시각아이디문제언어결과실행 시간메모리
1286042cowkimZoltan (COCI16_zoltan)C++20
0 / 140
388 ms131072 KiB
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <string> #include <math.h> #include <cctype> #include <cstdint> #include <climits> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <string> #include <math.h> #include <cctype> #include <cstdint> #include <climits> #include <iomanip> #define ll long long #define int ll #define endl "\n" using namespace std; ll MODNR = 1000000007; pair<int,int> getMax(pair<int,int> a, pair<int,int> b){ if(a.first == b.first) return {a.first,(a.second + b.second)%MODNR}; return a.first < b.first ? b: a; } struct segNode{ int nodel; int noder; pair<int,int> nodeMax; segNode* lNode = nullptr; segNode* rNode = nullptr; segNode(int nodel, int noder){ this->nodel = nodel; this->noder = noder; nodeMax = {0,1}; } void extend(){ if(lNode == nullptr){ int mid = (nodel + noder)/2; lNode = new segNode(nodel,mid); rNode = new segNode(mid,noder); } } pair<int,int> update(int pos, pair<int,int> change){ if(pos < nodel || noder <= pos) return nodeMax; if(nodel +1 == noder) return nodeMax = getMax(nodeMax,change); extend(); return nodeMax = getMax(lNode->update(pos,change), rNode->update(pos,change)); } pair<int,int> querie(int l, int r){ if(r <= nodel || noder <= l) return {0,1}; if(l<= nodel && noder <= r) return nodeMax; extend(); return getMax(lNode->querie(l,r),rNode->querie(l,r)); } }; signed main(){ //lathet segNode daSeg(0,MODNR); int n; cin >> n; vector<int> arr(n); for(int i = 0; i<n; i++){ cin >> arr[i]; } //bygg upp om de läggs på vänstra sidan for(int i = n-1; i>= 0; i--){ pair<int,int> best = daSeg.querie(0,arr[i]); best.first++; daSeg.update(arr[i],best); } for(int i = 0; i<n; i++){ pair<int,int> best = daSeg.querie(0,arr[i]); best.first++; daSeg.update(arr[i],best); } pair<int,int> best = daSeg.querie(0,MODNR); int restCombos = 1; int nrNumsLeft = n - best.first; for(int i = 0; i<nrNumsLeft; i++){ restCombos<<=1; restCombos%MODNR; } cout << (restCombos*best.second)%MODNR << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...