Submission #1799835
Source Code Expand
#include <stdio.h> #include <vector> #include <queue> #include <iostream> #include <string> #include <bitset> #include <map> #include <set> #include <tuple> #include <stack> #include <string.h> #include <time.h> #include <algorithm> using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; int main() { int n; scanf("%d", &n); vector<i64> arr(n); map<i64, int> pos; set<int> used; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); pos[arr[i]] = i; } i64 res = 0; for (int i = 1; i <= n; i++) { i64 k = pos[i]; auto iter = used.upper_bound(k); i64 lo = 0, hi = n - 1; if (iter != used.end()) { hi = *iter - 1; } if (iter != used.begin() && !used.empty()) { lo = *(--iter) + 1; } res += (k - lo + 1) * (hi - k + 1) * i; used.insert(k); } printf("%lld", res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | jwvg0425 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 949 Byte |
Status | AC |
Exec Time | 241 ms |
Memory | 23680 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:24:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:33:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld", &arr[i]); ^
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 | 241 ms | 23680 KB |
corner1 | AC | 238 ms | 23680 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 170 ms | 23680 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 215 ms | 23680 KB |
maxrand1 | AC | 215 ms | 23680 KB |
maxrand2 | AC | 216 ms | 23680 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |