Submission #51560644
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
struct line{
int l,r,flag;
};
vector<line>p[800005];
int x[800005],y[800005],xx[800005],yy[800005];
int totx,toty;vector<int>p1,p2;
struct node{
int sum;int l,r,lazy;
void add(int x){lazy+=x;}
}tree[4000005];
void push_up(int k){
if(tree[k].lazy == 0)tree[k].sum = tree[k<<1].sum+tree[k<<1|1].sum;
else tree[k].sum = p1[tree[k].r-1]-p1[tree[k].l-1];
}
void build(int l,int r,int k){
tree[k].l = l,tree[k].r = r;
if(l+1 == r){
return;
}build(l,l+r>>1,k<<1),build(l+r>>1,r,k<<1|1);
}void upd(int k,int l,int r,int add){
int ll = tree[k].l,rr = tree[k].r;
if(l>=rr or ll>=r)return ;
if(l<=ll and rr<=r){
tree[k].add(add);push_up(k);return;
}upd(k<<1,l,r,add),upd(k<<1|1,l,r,add);
push_up(k);
}vector<int>pos[200005];int N;
signed main(){
cin >> N;
for(int i = 1;i<=N;i++)pos[i].push_back(0);
for(int i=1;i<=N;i++){
int a;cin >> a;pos[a].push_back(i);
}for(int i= 1;i<=N;i++)pos[i].push_back(N+1);
for(int i= 1;i<=N;i++){
for(int j =0;j+2<pos[i].size();j++){
x[++n] = pos[i][j],y[n] = pos[i][j+1];
xx[n] = pos[i][j+1],yy[n] = pos[i][j+2];
}
}//for(int i = 1;i<=n;i++)cout << x[i] << " " << y[i] << " " << xx[i] << " " << yy[i] << endl;
for(int i = 1;i<=n;i++){
p1.push_back(x[i]);
p1.push_back(xx[i]);
p2.push_back(y[i]);
p2.push_back(yy[i]);
}sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
p1.erase(unique(p1.begin(),p1.end()),p1.end());
p2.erase(unique(p2.begin(),p2.end()),p2.end());
totx = p1.size(),toty = p2.size();
for(int i = 1;i<=n;i++){
x[i] = lower_bound(p1.begin(),p1.end(),x[i])-p1.begin()+1;
xx[i] = lower_bound(p1.begin(),p1.end(),xx[i])-p1.begin()+1;
y[i] = lower_bound(p2.begin(),p2.end(),y[i])-p2.begin()+1;
yy[i] = lower_bound(p2.begin(),p2.end(),yy[i])-p2.begin()+1;
line x1;x1.l = x[i],x1.r = xx[i];
x1.flag = 1;p[y[i]].push_back(x1);
x1.flag = -1;p[yy[i]].push_back(x1);
}build(1,totx+1,1);int ans = 0;
for(int i = 1;i<toty;i++){
for(auto x:p[i]){
upd(1,x.l,x.r,x.flag);
}ans+=tree[1].sum*(p2[i]-p2[i-1]);//assert(tree[1].sum<=p1.back()-p1[0]);
}cout<<ans <<endl;
return 0;
}
Submission Info
Submission Time
2024-03-23 21:14:15+0900
Task
G - Alone
User
juan_123
Language
C++ 20 (gcc 12.2)
Score
575
Code Size
2368 Byte
Status
AC
Exec Time
463 ms
Memory
62840 KiB
Compile Error
Main.cpp: In function ‘void build(long long int, long long int, long long int)’:
Main.cpp:23:15: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
23 | }build(l,l+r>>1,k<<1),build(l+r>>1,r,k<<1|1);
| ~^~
Main.cpp:23:34: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
23 | }build(l,l+r>>1,k<<1),build(l+r>>1,r,k<<1|1);
| ~^~
Main.cpp: In function ‘int main()’:
Main.cpp:39:33: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
39 | for(int j =0;j+2<pos[i].size();j++){
| ~~~^~~~~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
575 / 575
Status
Set Name
Test Cases
Sample
sample00.txt, sample01.txt, sample02.txt
All
sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt
Case Name
Status
Exec Time
Memory
sample00.txt
AC
5 ms
3432 KiB
sample01.txt
AC
5 ms
3444 KiB
sample02.txt
AC
5 ms
3568 KiB
testcase00.txt
AC
289 ms
61572 KiB
testcase01.txt
AC
308 ms
62764 KiB
testcase02.txt
AC
177 ms
59840 KiB
testcase03.txt
AC
188 ms
61856 KiB
testcase04.txt
AC
221 ms
59836 KiB
testcase05.txt
AC
228 ms
61960 KiB
testcase06.txt
AC
193 ms
59028 KiB
testcase07.txt
AC
209 ms
61924 KiB
testcase08.txt
AC
203 ms
59356 KiB
testcase09.txt
AC
218 ms
61840 KiB
testcase10.txt
AC
210 ms
60580 KiB
testcase11.txt
AC
219 ms
61824 KiB
testcase12.txt
AC
202 ms
58324 KiB
testcase13.txt
AC
222 ms
61828 KiB
testcase14.txt
AC
219 ms
60808 KiB
testcase15.txt
AC
224 ms
61952 KiB
testcase16.txt
AC
224 ms
61088 KiB
testcase17.txt
AC
231 ms
62068 KiB
testcase18.txt
AC
240 ms
59896 KiB
testcase19.txt
AC
255 ms
62224 KiB
testcase20.txt
AC
272 ms
59804 KiB
testcase21.txt
AC
287 ms
62120 KiB
testcase22.txt
AC
329 ms
62708 KiB
testcase23.txt
AC
330 ms
62760 KiB
testcase24.txt
AC
328 ms
59672 KiB
testcase25.txt
AC
352 ms
62244 KiB
testcase26.txt
AC
340 ms
58476 KiB
testcase27.txt
AC
378 ms
62840 KiB
testcase28.txt
AC
421 ms
62304 KiB
testcase29.txt
AC
427 ms
62580 KiB
testcase30.txt
AC
407 ms
58360 KiB
testcase31.txt
AC
463 ms
62532 KiB
testcase32.txt
AC
380 ms
59108 KiB
testcase33.txt
AC
418 ms
62436 KiB