Submission #59447862 - AtCoder Beginner Contest 378 (original) (raw)

Submission #59447862


Source Code Expand

#include #include using namespace std; class seguki{ public: //1index vectornum; int siz=1; void init(int n){ while(siz<n)siz*=2; for (int i=0;i<siz2+1;i++)num.emplace_back(0); } void update(int a,int b){ a=siz+a-1; num[a]=b; //上に更新 a/=2; while(a>=1){ num[a]=num[a2]+num[a2+1]; a/=2; } } //updateじゃなくて加算 void henkou(int a,int b){ a=siz+a-1; num[a]+=b; a/=2; while(a>=1){ num[a]=num[a2]+num[a2+1]; a/=2; } } //a,b半開区間 //sm_num(求めたい区間の半開区間(1~5だったら1,6),1,seguki.siz+1(セルのすべての半開区間),1(スタート地点のセル1)) int sm_num(int l,int r,int a,int b,int u){ if(r<=a || b<=l)return 0; else if(l<=a && b<=r)return num[u]; int m=(a+b)/2; int L=sm_num(l,r,a,m,u*2); int R=sm_num(l,r,m,b,u*2+1); return L+R; } }; int main() { long long n,m; cin >> n >> m; vectora(n); for(int i=0;i<n;i++)cin >> a[i]; seguki rotti; rotti.init(m); long long cnt=0,cnt2=0,ans=0; for(int i=0;i<n;i++){ cnt2+=cnt; cnt=(cnt+a[i])%m; ans+=cnt(i+1); ans-=cnt2; ans+=rotti.sm_num(cnt+1,m+1,1,rotti.siz+1,1)*m; rotti.henkou(cnt,1); } cout << ans << endl; }

Submission Info

Submission Time 2024-11-05 00:11:54+0900
Task E - Mod Sigma Problem
User rotti
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1376 Byte
Status AC
Exec Time 86 ms
Memory 8284 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status AC × 2 AC × 35
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3460 KB
00_sample_02.txt AC 1 ms 3596 KB
01_random_01.txt AC 3 ms 3648 KB
01_random_02.txt AC 60 ms 3932 KB
01_random_03.txt AC 27 ms 3552 KB
01_random_04.txt AC 58 ms 4000 KB
01_random_05.txt AC 7 ms 3548 KB
01_random_06.txt AC 62 ms 3852 KB
01_random_07.txt AC 57 ms 3936 KB
01_random_08.txt AC 59 ms 3972 KB
01_random_09.txt AC 12 ms 3456 KB
01_random_10.txt AC 61 ms 3964 KB
01_random_11.txt AC 67 ms 4864 KB
01_random_12.txt AC 85 ms 8048 KB
01_random_13.txt AC 52 ms 7700 KB
01_random_14.txt AC 85 ms 8152 KB
01_random_15.txt AC 36 ms 4152 KB
01_random_16.txt AC 85 ms 8052 KB
01_random_17.txt AC 22 ms 3924 KB
01_random_18.txt AC 85 ms 8124 KB
01_random_19.txt AC 84 ms 8096 KB
01_random_20.txt AC 85 ms 8112 KB
01_random_21.txt AC 69 ms 4904 KB
01_random_22.txt AC 85 ms 8048 KB
01_random_23.txt AC 31 ms 4180 KB
01_random_24.txt AC 86 ms 8060 KB
01_random_25.txt AC 40 ms 7760 KB
01_random_26.txt AC 85 ms 8148 KB
01_random_27.txt AC 79 ms 6152 KB
01_random_28.txt AC 85 ms 8116 KB
01_random_29.txt AC 28 ms 5560 KB
01_random_30.txt AC 85 ms 8284 KB
02_handmade_01.txt AC 3 ms 5236 KB
02_handmade_02.txt AC 37 ms 5500 KB
02_handmade_03.txt AC 86 ms 8068 KB