답안 #236819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236819 2020-06-03T13:44:28 Z egekabas 3단 점프 (JOI19_jumps) C++14
5 / 100
4000 ms 21364 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
struct querry{
    ll x, y, id;
};
ll sfunc(querry a, querry b){
    if(a.x/300 != b.x/300)
        return a.x < b.x;
    return a.y < b.y;
}
ll n;
ll a[500009];
ll q;
querry qu[500009];
ll ans[500009];
int main() {

    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    cin >> q;
    for(ll i = 0; i < q; ++i){
        cin >> qu[i].x >> qu[i].y;
        --qu[i].x;
        --qu[i].y;
        qu[i].id = i;
    }
    sort(qu, qu+q, sfunc);
    ll l = 0, r = -1;
    set<pll, greater<pll>> s;
    for(ll i = 0; i < q; ++i){
        while(r < qu[i].y){
            ++r;
            s.insert({a[r], r});
        }
        while(l > qu[i].x){
            --l;
            s.insert({a[l], l});    
        }
        while(r > qu[i].y){
            s.erase({a[r], r});
            --r;
        }
        while(l < qu[i].x){
            s.erase({a[l], l});
            ++l;
        }
        vector<pll> v;
        auto it = s.begin();
        for(ll j = 0; j < 30 && it != s.end(); ++j){
            v.pb({(*it).ss, (*it).ff});
            ++it;
        }
        sort(v.begin(), v.end());
        for(ll i1 = 0; i1 < v.size(); ++i1)
            for(ll i2 = i1+1; i2 < v.size(); ++i2)
                for(ll i3 = i2+1; i3 < v.size(); ++i3)
                    if(v[i2].ff-v[i1].ff <= v[i3].ff-v[i2].ff)
                        ans[qu[i].id] = max(ans[qu[i].id], v[i1].ss+v[i2].ss+v[i3].ss);
    }
    for(ll i = 0; i < q; ++i)
        cout << ans[i] << '\n';
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:69:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(ll i1 = 0; i1 < v.size(); ++i1)
                        ~~~^~~~~~~~~~
jumps.cpp:70:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(ll i2 = i1+1; i2 < v.size(); ++i2)
                               ~~~^~~~~~~~~~
jumps.cpp:71:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(ll i3 = i2+1; i3 < v.size(); ++i3)
                                   ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 436 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 436 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Execution timed out 4056 ms 21364 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 16120 KB Output is correct
2 Correct 168 ms 16376 KB Output is correct
3 Correct 165 ms 16248 KB Output is correct
4 Correct 245 ms 16120 KB Output is correct
5 Correct 244 ms 16120 KB Output is correct
6 Incorrect 163 ms 15548 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 436 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Execution timed out 4056 ms 21364 KB Time limit exceeded
12 Halted 0 ms 0 KB -