Submission #1348677
Source Code Expand
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define INF 1e9+7
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void readf(string x){
freopen((x+".in").c_str(),"r",stdin);
freopen((x+".out").c_str(),"w",stdout);
}
void pr(string x){
freopen((x+".in").c_str(),"w",stdout);
}
int read()
{
bool min = 0;
int result = 0;
char ch;
ch = getchar();
while(1)
{
if(ch == '-') break;
if(ch >='0' && ch <= '9') break;
ch = getchar();
}
if(ch == '-') min = 1;else result = ch-'0';
while(1)
{
ch =getchar();
if(ch< '0' || ch>'9') break;
result = result * 10 + (ch-'0');
}
if(min) return -result;
return result;
}
//Reynaldo's Template
int main(){
map<ll,ll> cnt,mini;
int N;
cin >> N;
ll gg = 0;
ll ans[N+5],sum = 0;
memset(ans,0,sizeof ans);
for(ll i=1;i<=N;i++){
ll a;
cin >> a;
gg = max(gg,a);
if(mini[a] == 0)
mini[a] = i;
else mini[a] = min(mini[a],i);
cnt[a]++;
}
cnt[0] = 1;
mini[0] = 1;
ll ban = cnt[gg];
ll mi = mini[gg];
ll pos = gg;
map<ll,ll>::iterator it = mini.end();
it--;
it--;
for(;;it--){
int r = it->first,t = it->second;
ans[mi] += (pos-r) * ban;
// cout << pos << " " << r << " " << ban << mi << " " << ans[mi]<< "\n";
pos = r;
ban += cnt[pos];
mi = min(mi,mini[pos]);
// cout << ban << " " << mi << " " << pos << " " << r << "\n";
if(it == mini.begin())break;
}
for(int i=1;i<=N;i++){
cout << ans[i] << "\n";
}
//cout << "\n";
}
Submission Info
Submission Time |
|
Task |
E - Frequency |
User |
rwhendry |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2068 Byte |
Status |
AC |
Exec Time |
166 ms |
Memory |
14336 KB |
Compile Error
./Main.cpp: In function ‘void readf(std::string)’:
./Main.cpp:26:38: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen((x+".in").c_str(),"r",stdin);
^
./Main.cpp:27:40: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen((x+".out").c_str(),"w",stdout);
^
./Main.cpp: In function ‘void pr(std::string)’:
./Main.cpp:31:39: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen((x+".in").c_str(),"w",stdout);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_example_01.txt, 00_example_02.txt |
All |
00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
AC |
1 ms |
256 KB |
00_example_02.txt |
AC |
1 ms |
256 KB |
01.txt |
AC |
1 ms |
256 KB |
02.txt |
AC |
7 ms |
896 KB |
03.txt |
AC |
1 ms |
256 KB |
04.txt |
AC |
2 ms |
256 KB |
05.txt |
AC |
1 ms |
256 KB |
06.txt |
AC |
1 ms |
256 KB |
07.txt |
AC |
1 ms |
256 KB |
08.txt |
AC |
1 ms |
256 KB |
09.txt |
AC |
9 ms |
1152 KB |
10.txt |
AC |
1 ms |
256 KB |
11.txt |
AC |
102 ms |
8960 KB |
12.txt |
AC |
102 ms |
8960 KB |
13.txt |
AC |
102 ms |
8960 KB |
14.txt |
AC |
104 ms |
8960 KB |
15.txt |
AC |
102 ms |
8960 KB |
16.txt |
AC |
56 ms |
1280 KB |
17.txt |
AC |
158 ms |
14080 KB |
18.txt |
AC |
166 ms |
13696 KB |
19.txt |
AC |
26 ms |
1152 KB |
20.txt |
AC |
77 ms |
6144 KB |
21.txt |
AC |
1 ms |
256 KB |
22.txt |
AC |
1 ms |
256 KB |
23.txt |
AC |
1 ms |
256 KB |
24.txt |
AC |
6 ms |
1024 KB |
25.txt |
AC |
1 ms |
256 KB |
26.txt |
AC |
2 ms |
384 KB |
27.txt |
AC |
1 ms |
256 KB |
28.txt |
AC |
106 ms |
14208 KB |
29.txt |
AC |
114 ms |
14336 KB |
30.txt |
AC |
128 ms |
14336 KB |
31.txt |
AC |
107 ms |
14208 KB |
32.txt |
AC |
108 ms |
14208 KB |
33.txt |
AC |
107 ms |
13696 KB |
34.txt |
AC |
114 ms |
13696 KB |
35.txt |
AC |
126 ms |
13696 KB |
36.txt |
AC |
109 ms |
13696 KB |
37.txt |
AC |
108 ms |
13696 KB |