답안 #870123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870123 2023-11-07T02:20:42 Z hqminhuwu Zoltan (COCI16_zoltan) C++14
0 / 140
3 ms 10780 KB
#include <bits/stdc++.h>
#define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <ll,ll>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define file "test"


using namespace std;
const int N = 5e5 + 5;
const ll oo = 1e9;
const ll mod = 1e9 + 7;

int i,n,a[N];
pii bit[N];
pll ans;

ll modpow (ll u, ll v){
    if (v == 0)
        return 1;
    ll tmp = modpow(u,v / 2);
    tmp = (tmp * tmp) % mod;
    if (v & 1)
        return (tmp * u) % mod;
    return tmp;
}
void update1 (int u, pll len){
    for (; u <= n; u += u & -u)
    if (bit[u].st < len.st)
        bit[u] = len;
    else if (bit[u].st == len.st)
        (bit[u].nd += len.nd) %= mod;
}

pll get1 (int u){
    pll res = {0,1};
    for (; u > 0; u -= u & -u)
    if (res.st < bit[u].st)
        res = bit[u];
    else if (res.st == bit[u].st)
        (res.nd += bit[u].nd) %= mod;
    return res;
}

void update2 (int u, pll len){
    for (; u > 0; u -= u & -u)
    if (bit[u].st < len.st)
        bit[u] = len;
    else if (bit[u].st == len.st)
        (bit[u].nd += len.nd) %= mod;
}

pll get2 (int u){
    pll res = {0,1};
    for (; u <= n; u += u & -u)
    if (res.st < bit[u].st)
        res = bit[u];
    else if (res.st == bit[u].st)
        (res.nd += bit[u].nd) %= mod;
    return res;
}
void compr(){
    vector <int> w;
    forr (i,1,n)
        w.pb(a[i]);
    sort(all(w));
    w.erase(unique(all(w)),w.end());
    forr (i,1,n)
        a[i] = lower_bound(all(w),a[i]) - w.begin() + 1;
}

pll p[N],s[N];
vector <int> v;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
   // #ifndef ONLINE_JUDGE
       freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
   // #endif
    cin >> n;
    forr (i,1,n)
        cin >> a[i];
    compr();
    ford (i,n,1){
        pii u = get1(a[i] - 1);
        p[i] = {u.st + 1,u.nd};
        update1(a[i],p[i]);
    }
    memset(bit,0,sizeof bit);
    ford (i,n,1){
        pii u = get2(a[i] + 1);
        s[i] = {u.st + 1,u.nd};
        update2(a[i],s[i]);
    }
    memset(bit,0,sizeof bit);
    forr (i,1,n){
     //   cout << a[i] << " " << p[i].st << " " << p[i].nd << " " << s[i].st << " " << s[i].nd << "\n";
        pll k = get1(a[i] - 1);
        pll w = {k.st + s[i].st,(k.nd *s[i].nd) % mod};
        if (w.st > ans.st)
            ans = w;
        else if (ans.st == w.st)
            ans.nd = (ans.nd + w.nd) % mod;
   //         cout << i << " " << ans.st << " " << ans.nd << "\n";
      //  if (i == 1)
        update1(a[i],p[i]); 
    }
    cout << ans.st << " ";
   // cout << 2 * modpow (2,mod - 2) << "\n";
    cout << (ans.nd * modpow(2,n - ans.st)) % mod;
    return 0;
}
/*



*/

Compilation message

zoltan.cpp: In function 'int main()':
zoltan.cpp:98:28: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment; use assignment instead [-Wclass-memaccess]
   98 |     memset(bit,0,sizeof bit);
      |                            ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from zoltan.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
  211 |     struct pair
      |            ^~~~
zoltan.cpp:104:28: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment; use assignment instead [-Wclass-memaccess]
  104 |     memset(bit,0,sizeof bit);
      |                            ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from zoltan.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
  211 |     struct pair
      |            ^~~~
zoltan.cpp:87:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:87:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10584 KB Output isn't correct
2 Incorrect 3 ms 10588 KB Output isn't correct
3 Incorrect 3 ms 10588 KB Output isn't correct
4 Incorrect 3 ms 10588 KB Output isn't correct
5 Incorrect 3 ms 10588 KB Output isn't correct
6 Incorrect 3 ms 10588 KB Output isn't correct
7 Incorrect 3 ms 10588 KB Output isn't correct
8 Incorrect 3 ms 10588 KB Output isn't correct
9 Incorrect 3 ms 10588 KB Output isn't correct
10 Incorrect 3 ms 10780 KB Output isn't correct
11 Incorrect 3 ms 10588 KB Output isn't correct
12 Incorrect 3 ms 10588 KB Output isn't correct
13 Incorrect 3 ms 10588 KB Output isn't correct
14 Incorrect 3 ms 10588 KB Output isn't correct
15 Incorrect 3 ms 10588 KB Output isn't correct
16 Incorrect 3 ms 10588 KB Output isn't correct
17 Incorrect 3 ms 10588 KB Output isn't correct
18 Incorrect 3 ms 10588 KB Output isn't correct
19 Incorrect 3 ms 10588 KB Output isn't correct
20 Incorrect 3 ms 10588 KB Output isn't correct