Submission #114523

#TimeUsernameProblemLanguageResultExecution timeMemory
114523MeloricGlobal Warming (CEOI18_glo)C++14
100 / 100
178 ms5728 KiB
#include <bits/stdc++.h> #define pb push_back #define X first #define Y second #define pii pair<int, int> #define lb lower_bound using namespace std; int n, x; vector<int> in, srt; struct ft{ vector<int> fen; ft(int N){ fen.assign(N+1, 0); } int qer(int a){ a++; int ans = 0; for(;a>0; a-=a&(-a))ans=max(ans, fen[a]); return ans; } void upd(int a, int b){ a++; for(;a<fen.size(); a+=a&(-a))fen[a]=max(b, fen[a]); } }; int main(){ cin >> n >> x; for(int i = 0; i<n; i++){ int c; cin >> c; in.pb(c); srt.pb(c); } sort(srt.begin(), srt.end()); ft yes(n), no(n); for(auto i : in){ int id = lb(srt.begin(), srt.end(), i)-srt.begin(); int tmp = no.qer(id-1); int nid = lb(srt.begin(), srt.end(), i+x)-srt.begin(); int tmp2 = no.qer(nid-1); no.upd(id, tmp+1); tmp = yes.qer(id-1); tmp = max(tmp, tmp2); yes.upd(id, tmp+1); } cout << yes.qer(n-1); return 0; }

Compilation message (stderr)

glo.cpp: In member function 'void ft::upd(int, int)':
glo.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(;a<fen.size(); a+=a&(-a))fen[a]=max(b, fen[a]);
              ~^~~~~~~~~~~
#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...