QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111697#5500. Barsxaphoenix#AC ✓334ms23128kbC++172.6kb2023-06-07 22:24:092023-06-07 22:24:14

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 22:24:14]
  • 评测
  • 测评结果:AC
  • 用时:334ms
  • 内存:23128kb
  • [2023-06-07 22:24:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC ch[k][0] 
#define RC ch[k][1]
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)

typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const int N = 500010;
const int M = 610000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const double eps = 1e-9;
inline int dcmp(double x) {
    return (x > eps) - (x < -eps);
}

struct Point {
    LL x, y;
    Point (LL x = 0 , LL y = 0) : x(x) , y(y) {}
    void input() {
        cin >> x >> y; 
    }
    bool operator < (const Point& R) const {
        if (x - R.x == 0)
            return (y - R.y) < 0;
        return (x - R.x) < 0;
    }
    bool operator == (const Point& R) const {
        return (x - R.x) == 0 && (y - R.y) == 0;
    }
    Point operator + (const Point& R) const {
        return Point(x + R.x, y + R.y);
    }
    Point operator - (const Point& R) const {
        return Point(x - R.x, y - R.y);
    }
    Point operator * (const LL& R) const {
        return Point(x * R, y * R);
    }
    /*
    Point operator / (const double& R) const {
        return Point(x / R, y / R);
    }
    */
    LL operator ^ (const Point& R) const {
        return x * R.y - y * R.x;
    }
    LL operator % (const Point& R) const {
        return x * R.x + y * R.y;
    }
    LL slen() {
        return *this % *this;
	}
    /*
    double len() {
        return sqrt(*this % *this);
	}
    double angle() {
        return atan2(y, x);
    } */
}p[N], h[N];

int tp, n;
int stk[N], used[N];

void convex(){
	tp = 0;
	//std::sort(p + 1, p + 1 + n); 
	stk[++tp] = 1;
	for (int i = 2; i <= n; ++i) {
	  while (tp >= 2 
	        && ((p[stk[tp]] - p[stk[tp - 1]]) ^ (p[i] - p[stk[tp]])) >= 0)
	    used[stk[tp--]] = 0;
	  used[i] = 1;  
	  stk[++tp] = i;
	}
	for (int i = 1; i <= tp; ++i) 
	  h[i] = p[stk[i]];
}

void solve() {
	cin >> n; 
	repn(i, 1, n) {
		cin >> p[i].y;
		p[i].x = i;
		used[i] = 0;
	}
	convex();
	LL ans = 0;
	repn(i, 2, tp) {
		ans += (h[i].x - h[i - 1].x) * (h[i].y + h[i - 1].y);
	}
	cout << ans << "\n";
}

int main()
{
	IO;
	int T;
	cin >> T;
	repn(i, 1, T) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 21136kb

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 297ms
memory: 21132kb

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
382465638565
663641330002
550288673161
458946673513
296420749955
875760099157
632854843886
586309163102
225238173690
716890380495
466644027129
283505446030
585094154153
201707398762
336548832140
483300272586
606382970973
587469399170
408018096564
827347820764
975377092201
925120038848
26408806...

result:

ok 10000 lines

Test #3:

score: 0
Accepted
time: 334ms
memory: 23128kb

input:

6
500000
287001636 204980186 997392401 188445265 873977784 672984447 520446063 460936121 420229946 413937980 95267858 869951831 87353679 843288346 375704325 376217775 66621398 502675506 854835633 99408891 880520553 944446461 690146628 632137514 179514334 551490018 981073461 196185611 719601446 93667...

output:

999978185027008
499999063998982
999946405821678
999970304287364
499999737998030
999979204653771

result:

ok 6 lines

Test #4:

score: 0
Accepted
time: 314ms
memory: 22956kb

input:

6
500000
669619127 356830845 494606145 526755381 169647973 602343819 658032437 326960015 207942215 173060393 217232953 314912605 366676785 510103533 489446303 121223259 374781515 484954847 134957195 400053837 122117455 627813351 583524019 624468283 613073257 263488687 242182189 527854337 554306009 1...

output:

953660650057664
883167999492927
499223754839723
667315106896885
904445177106028
879334018232172

result:

ok 6 lines

Test #5:

score: 0
Accepted
time: 315ms
memory: 23120kb

input:

6
500000
12403960 2930024 1808469 4773510 8417429 6369605 2751412 4062450 9895452 9966727 11476617 4854207 2807239 9516332 5730691 731629 2368916 1351133 1435333 6860794 5460899 2506776 7936802 12585522 8631641 3397564 316192 11362360 10913499 5967508 7437490 12648666 5703570 637890 7908197 361480 8...

output:

667267911235251
678790984141243
666630987914525
671493601773996
717382005630376
667971386351316

result:

ok 6 lines