Submission #1025703

# Submission time Handle Problem Language Result Execution time Memory
1025703 2024-07-17T08:56:15 Z _rain_ Zoltan (COCI16_zoltan) C++14
140 / 140
168 ms 14796 KB
#include<bits/stdc++.h>
using namespace std;

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
namespace Random
{
    #define int long long
    int Rand(int l , int r)
    {
        return uniform_int_distribution<int>(l , r)(rng);
    }
    #undef int 
}

using i64 = long long;
using ui64 = unsigned long long;

#define MASK(x) ((i64)(1) << (x))
#define BIT(mask , x) (((mask) >> (x)) & (1))
#define sz(x) (x).size()
#define all(x) (x).begin() , (x).end()

#define FOR(i ,a , b) for (int i = (a); i <= (b); ++i)
#define FORD(i , a , b) for (int i = (b); i >= (a); --i)
#define REP(i , a , b) for (int i = (a); i < (b); ++i)
#define REPD(i , a , b) for (int i = (b) - 1 ; i >= (a); --i)

template <class T> 
    void compress(vector<T> &a)
    {
        sort(a.begin() , a.end());
        a.resize(unique(a.begin() , a.end()) - a.begin());
        return;
    }
template<class T>
    void printArr(T& container , string separator = "" , string finish = "\n")
    {
        for (auto& item : container) cout << item << separator;
        cout << finish;
    }

template<class T>
    bool maximize(T &a , T b) {if (a < b) return a = b , true; else return false;}
template<class T>
    bool minimize(T &a , T b) {if (a > b) return a = b , true; else return false;}
template<class T>
    T gcd(T x , T y) {while (y) swap(y , x %= y); return x;}
template<class T>
    T lcm(T x , T y) {return (x * y) / gcd(x , y);}

//... INPUT
    void INPUT(string name)
    {
        iostream::sync_with_stdio(false); cin.tie(0);
        if (!fopen((name + ".inp").c_str() , "r")) return;
        freopen((name + ".inp").c_str() , "r" , stdin);
        freopen((name + ".out").c_str() , "w+" , stdout);
    }

const int maxn = 2e5;
//... MOD OPERATOR
    const int MOD = 1e9 + 7;
    int add(int a , int b)
    {
        return (a + b >= MOD ? a + b - MOD : a + b);
    }
    int mul(int a , int b)
    {
        return (i64)a * b % MOD;
    }
    int binpow(int a , int b)
    {
        int res = 1;
        for (; b; b >>= 1 , a = mul(a,a))
            if (b&1) res = mul(res , a);
        return res;
    }
//... FEN
    class segment
    {
    public:
        vector<pair<int,int>> st;
        void init(int n)
        {
            st.assign(n*4+2,{0,0});
            return;
        }
        pair<int,int> pushup(pair<int,int>a , pair<int,int> b)
        {
            if (a.first > b.first) return a;
            if (b.first > a.first) return b;
            return {a.first , add(a.second , b.second)};
        }
        void update(int node , int l , int r , int pos , pair<int,int> val)
        {
            if (l > pos || r < pos) return;
            if (l == r)     
            {
                if (st[node].first < val.first) st[node] = val;
                    else if (st[node].first == val.first) st[node].second = add(st[node].second , val.second);
            }
            else 
            {
                int m = l + r >> 1;
                update(node*2,l,m,pos,val);
                update(node*2+1,m+1,r,pos,val);
                st[node] = pushup(st[node*2] , st[node*2+1]);
            }
            return;
        }
        pair<int,int> get(int node , int l , int r , int u , int v)
        {
            if (l > v || r < u) return {0,0};
            if (u <= l && r <= v) return st[node];
            int m = l + r >> 1;
            pair<int,int> g1 = get(node*2,l,m,u,v);
            pair<int,int> g2 = get(node*2+1,m+1,r,u,v);
            return pushup(g1,g2);
        }
    };

segment st1 , st2;
int n , a[maxn + 2];

int32_t main()
{
    INPUT("main");
        cin >> n;
        vector<int> value;
        FOR(i,1,n) 
            {
                cin >> a[i];
                value.push_back(a[i]);
            }
        compress(value);
        int length = n;
        st1.init(length); st2.init(length);
        FOR(i,1,n) 
                a[i] = upper_bound(all(value),a[i]) - value.begin();
        int mxlength = 0 , cnt = 0;
        FORD(i,1,n)
        {
            pair<int,int> c1 = st1.get(1,1,length,1,a[i]-1);
            pair<int,int> c2 = st2.get(1,1,length,a[i] + 1,length);
            maximize(c1.second , 1);
            maximize(c2.second , 1);
            if (maximize(mxlength , c1.first + c2.first + 1)) cnt = mul(c1.second , c2.second);
                else if (mxlength == c1.first + c2.first + 1) cnt = add(cnt , mul(c1.second , c2.second));    
            c1.first++; c2.first++; 
            st1.update(1,1,length,a[i],c1);
            st2.update(1,1,length,a[i],c2);
        }

        cout << mxlength << ' ' << mul(cnt , binpow(2 , n - mxlength));
    cerr << "\nTIME RUN : " << 1000 * clock()/CLOCKS_PER_SEC << " MS \n";

}
/** lockheed martin build me - Red Bull boost me **/

Compilation message

zoltan.cpp: In member function 'void segment::update(int, int, int, int, std::pair<int, int>)':
zoltan.cpp:104:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  104 |                 int m = l + r >> 1;
      |                         ~~^~~
zoltan.cpp: In member function 'std::pair<int, int> segment::get(int, int, int, int, int)':
zoltan.cpp:115:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  115 |             int m = l + r >> 1;
      |                     ~~^~~
zoltan.cpp: In function 'void INPUT(std::string)':
zoltan.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen((name + ".inp").c_str() , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen((name + ".out").c_str() , "w+" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 540 KB Output is correct
11 Correct 97 ms 11632 KB Output is correct
12 Correct 81 ms 10196 KB Output is correct
13 Correct 76 ms 9696 KB Output is correct
14 Correct 112 ms 10188 KB Output is correct
15 Correct 148 ms 12668 KB Output is correct
16 Correct 168 ms 14540 KB Output is correct
17 Correct 130 ms 14796 KB Output is correct
18 Correct 118 ms 14540 KB Output is correct
19 Correct 119 ms 14548 KB Output is correct
20 Correct 121 ms 14456 KB Output is correct