Submission #149141

# Submission time Handle Problem Language Result Execution time Memory
149141 2019-09-01T05:48:55 Z 팀명못정해서15시간째고민중인팀(#3792, onjo0127, sg1774) Crosses on the Grid (FXCUP4_cross) C++17
100 / 100
259 ms 6764 KB
#include "cross.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define X first
#define Y second

pii A[200009];
int F[200009];
vector<int> X;

void upd(int x, int y) {
    for(int i=x; i<=X.size(); i+=(i&-i)) F[i] += y;
}

int get(int x) {
    int s = 0;
    for(int i=x; i>=1; i-=(i&-i)) s += F[i];
    return s;
}

int getx(int x) {
    return lower_bound(X.begin(), X.end(), x) - X.begin() + 1;
}

long long SelectCross(int K, vector<int> I, vector<int> O) {
	int N = I.size();
	for(int i=0; i<N; i++) {
        A[i] = {I[i], O[i]};
        X.push_back(O[i]);
	}
	sort(A, A+N); reverse(A, A+N);
	sort(X.begin(), X.end()); X.resize(unique(X.begin(), X.end()) - X.begin());
	long long ans = 0;
	for(int i=0; i<N; i++) {
        upd(getx(A[i].Y), +1);
        if(i+1 >= K) {
            int l = 0, r = X.size();
            while(l <= r) {
                int m = l+r >> 1;
                if(i+1 - get(m) >= K) {
                    ans = max(ans, (2LL*X[m] - A[i].X) * A[i].X);
                    l = m+1;
                }
                else r = m-1;
            }
        }
	}
	return ans;
}

Compilation message

cross.cpp: In function 'void upd(int, int)':
cross.cpp:13:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=x; i<=X.size(); i+=(i&-i)) F[i] += y;
                  ~^~~~~~~~~~
cross.cpp: In function 'long long int SelectCross(int, std::vector<int>, std::vector<int>)':
cross.cpp:40:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
                 int m = l+r >> 1;
                         ~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 17 ms 896 KB Output is correct
6 Correct 259 ms 6628 KB Output is correct
7 Correct 228 ms 6752 KB Output is correct
8 Correct 215 ms 6764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 17 ms 896 KB Output is correct
6 Correct 259 ms 6628 KB Output is correct
7 Correct 228 ms 6752 KB Output is correct
8 Correct 215 ms 6764 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 16 ms 896 KB Output is correct
13 Correct 109 ms 3684 KB Output is correct
14 Correct 220 ms 6756 KB Output is correct
15 Correct 213 ms 6764 KB Output is correct
16 Correct 205 ms 6760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 17 ms 896 KB Output is correct
6 Correct 259 ms 6628 KB Output is correct
7 Correct 228 ms 6752 KB Output is correct
8 Correct 215 ms 6764 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 16 ms 896 KB Output is correct
13 Correct 109 ms 3684 KB Output is correct
14 Correct 220 ms 6756 KB Output is correct
15 Correct 213 ms 6764 KB Output is correct
16 Correct 205 ms 6760 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 15 ms 896 KB Output is correct
20 Correct 107 ms 3692 KB Output is correct
21 Correct 175 ms 5608 KB Output is correct
22 Correct 202 ms 6752 KB Output is correct
23 Correct 204 ms 6760 KB Output is correct
24 Correct 209 ms 6764 KB Output is correct
25 Correct 187 ms 6752 KB Output is correct
26 Correct 168 ms 6764 KB Output is correct