Submission #287621

# Submission time Handle Problem Language Result Execution time Memory
287621 2020-08-31T21:24:54 Z jainbot27 Secret (JOI14_secret) C++17
0 / 100
522 ms 8440 KB
//author: JainBot27
//Created on: 08/31/20
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, y, z) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, z, 0)
#define trav(x, y) for(auto&x:y)


const string nl = "\n";
using ll = int64_t;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#include "secret.h"
int a[1001], n, dp[1001][1001];

//int secret(int a, int b){
    //return -69;
//}
void go(int l = 0, int r = n-1){
    int m = (l + r)/2;
    dp[m][m]=a[m];
    dp[m+1][m+1]=a[m+1];
    //ROF(i,m,l){ 
        //dp[m][i] = Secret(dp[m][i+1], a[i]);
    //}
    for(int i=m-1; i >= l; i--){ 
        dp[m][i] = Secret(dp[m][i+1], a[i]);
    }
    FOR(i,m+2,r+1){
        dp[m+1][i] = Secret(dp[m+1][i-1], a[i]);
    }
    if(l<m)go(l,m);
    if(m+1<r)go(m+1,r);
}
void Init(int N, int A[]){
    F0R(i, N) a[i]=A[i];
    n=N;
    go();
}
int Query(int A, int B){
    int l = 0, r = n-1;
    while(l != r){
        int m = (l + r)/2;
        if(m==B){
            return dp[m][A];
        }
        else if(m >= A && m < B){
            return Secret(dp[m][A], dp[m+1][B]);
        }
        else if(m < A){
            l = m + 1; 
        }
        else{
            r = m;
        }
    }
    return dp[l][r];
}
/*
int main(){
    int n; cin >> n;
    int x[8];
    for(int i=0; i < n; i++){
        cin >> x[i]; 
    }
    Init(n, x);
    int q; cin >> q;
    for(int i =0; i < q; i++){
        int c, v; cin >> c >> v;
        cout << Query(c,v) << nl;
    }
}
/*
 * Stuff I should try:
 * Is it Monotonic? -> Binary Search
 * Is N small? -> Bitsets or other exponential
 * Edge Cases? Look Carefully 
 * Can't figure anything out? Brute Force and see patterns
 * Try to prove greedies
 * Prefix Sums, Amortization, DP, Data Structures
*/



Compilation message

secret.cpp:136:1: warning: "/*" within comment [-Wcomment]
  136 | /*
      |
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 4472 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 268854015.
2 Incorrect 137 ms 4472 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 311474560.
3 Incorrect 140 ms 4488 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 353554500.
4 Incorrect 511 ms 8312 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 343081568.
5 Incorrect 512 ms 8408 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 957013316.
6 Incorrect 512 ms 8312 KB Wrong Answer: Query(200, 208) - expected : 277813445, actual : 154975445.
7 Incorrect 522 ms 8312 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 675449873.
8 Incorrect 515 ms 8312 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 273091792.
9 Incorrect 513 ms 8440 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 827853577.
10 Incorrect 522 ms 8440 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 337854787.