Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class InParser {
- private:
- FILE *fin;
- char *buff;
- int sp;
- char read_ch() {
- ++sp;
- if (sp == 4096) {
- sp = 0;
- fread(buff, 1, 4096, fin);
- }
- return buff[sp];
- }
- public:
- InParser(const char* nume) {
- fin = fopen(nume, "r");
- buff = new char[4096]();
- sp = 4095;
- }
- InParser& operator >> (int &n) {
- char c;
- while (!isdigit(c = read_ch()) && c != '-');
- int sgn = 1;
- if (c == '-') {
- n = 0;
- sgn = -1;
- } else {
- n = c - '0';
- }
- while (isdigit(c = read_ch())) {
- n = 10 * n + c - '0';
- }
- n *= sgn;
- return *this;
- }
- InParser& operator >> (long long &n) {
- char c;
- n = 0;
- while (!isdigit(c = read_ch()) && c != '-');
- long long sgn = 1;
- if (c == '-') {
- n = 0;
- sgn = -1;
- } else {
- n = c - '0';
- }
- while (isdigit(c = read_ch())) {
- n = 10 * n + c - '0';
- }
- n *= sgn;
- return *this;
- }
- };
- int n, x;
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- InParser _cin("gogosi.in");
- ofstream cout("gogosi.out");
- vector < int > v;
- _cin >> n >> x;
- v.push_back( x );
- for (int i = 1; i < n; i++){
- _cin >> x;
- int left = 0; int right = v.size() - 1;
- while (right > left){
- int mid = (left + right) / 2;
- if (v[ mid ] <= x)
- right = mid;
- else
- left = mid + 1;
- }
- if (v[ right ] <= x)
- v[ right ] = x;
- else
- v.push_back( x );
- }
- cout << v.size();
- }
Advertisement
Add Comment
Please, Sign In to add comment