Submission #1819042
Source Code Expand
#include <bits/stdc++.h> #define pb push_back #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef pair<int, int> pii; typedef vector<pii> vpii; const int N=300000; int p[N], lr[N]; int main() { int i, j, t, n; ll L, R, ans=0; scanf("%d", &n); for(i=1; i<=n; i++) { scanf("%d", &t); p[t]=i; } for(i=n; i>=1; i--) { j=p[i]; L=lr[j-1]; if(!L) L=j; R=lr[j+1]; if(!R) R=j; ans+=i*(j-L+1)*(R-j+1); lr[L]=R; lr[R]=L; } printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | Ajira |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 762 Byte |
Status | AC |
Exec Time | 25 ms |
Memory | 1792 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:22:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:24:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &t); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2 |
All | corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
corner0 | AC | 21 ms | 1792 KB |
corner1 | AC | 21 ms | 1792 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 22 ms | 1792 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 24 ms | 1792 KB |
maxrand1 | AC | 24 ms | 1792 KB |
maxrand2 | AC | 25 ms | 1792 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |