#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e9;
const int INF = 1e9;
const ll mod2 = 1e9+7;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
double a;
int b;
};
struct ic
{
ll a;
int b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,lim,w,l,r ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
struct skibidi
{
ib dsu[1000001];
void reset(int x)
{
dsu[x]= {1,x};
s4++;
if(dsu[x-1].a!=0)noi(x,x-1);
if(dsu[x+1].a!=0)noi(x,x+1);
}
int get(int x)
{
if(dsu[x].b==x) return x;
return dsu[x].b=get(dsu[x].b);
}
int cost(int x)
{
return x*(x+1)/2;
}
void noi(int x,int y)
{
x=get(x);
y=get(y);
if(x==y) return;
if(dsu[x].a<dsu[y].a)swap(x,y);
s4-=cost(dsu[y].a);
s4-=cost(dsu[x].a);
dsu[x].a+=dsu[y].a;
s4+=cost(dsu[x].a);
dsu[y].b=x;
}
} ds;
int h[1000001];
int ans[1000001];
vector<ib> v,ask;
bool cmp(ib a,ib b)
{
return a.a<b.a;
}
void phongbeo()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
cin>>h[i];
for(int i=1; i<=n; i++)
v.pb({h[i],i});
sort(v.begin(),v.end(),cmp);
for(int i=1; i<=m; i++)
{
cin>>l;
ask.pb({l,i});
}
sort(ask.begin(),ask.end(),cmp);
l=0;
for(auto x:ask)
{
while(l<v.size()&&v[l].a<=x.a)
{
ds.reset(v[l].b);
l++;
}
ans[x.b]=s4;
}
for(int i=1; i<=m; i++)
cout<<ans[i]<<"\n";
}
Compilation message (stderr)
pilot.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
76 | main()
| ^~~~
pilot.cpp: In function 'void phongbeo()':
pilot.cpp:134:18: warning: narrowing conversion of 'h[i]' from 'long long int' to 'double' [-Wnarrowing]
134 | v.pb({h[i],i});
| ~~~^
pilot.cpp:139:17: warning: narrowing conversion of 'l' from 'long long int' to 'double' [-Wnarrowing]
139 | ask.pb({l,i});
| ^
pilot.cpp: In function 'int main()':
pilot.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
pilot.cpp:80:9: note: in expansion of macro 'fin'
80 | fin(task);
| ^~~
pilot.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
pilot.cpp:81:9: note: in expansion of macro 'fou'
81 | fou(task);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |