QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374766#3727. Nice Trickucup-team1251AC ✓79ms12680kbC++17958b2024-04-02 17:57:022024-04-02 17:57:03

Judging History

你现在查看的是最新测评结果

  • [2024-04-02 17:57:03]
  • 评测
  • 测评结果:AC
  • 用时:79ms
  • 内存:12680kb
  • [2024-04-02 17:57:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6 + 10;
const ll P = 1e9 + 7;
ll t, n, m;
ll a[N];
ll b[N];
ll pre[N];
ll suf[N];
void ac() {
	while (cin >> n) {
        for(int i = 0;i<=n+3;i++)
        {
            suf[i] = 0;
            pre[i] = 0;
            b[i] = 0;
            a[i] = 0;
        }
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			pre[i] = pre[i - 1] + a[i];
            pre[i]%=P;
		}
		for(int i = n;i>=1;i--)
		{
			suf[i] = suf[i+1]+a[i];
            suf[i]%=P;
		}
		if (n <= 3) {
			cout << "0\n";
		} else {
			b[2] = (a[1]%P * a[2]%P)%P;
//			b[3] = b[2]+pre[2]*a[3];
			ll ans=0;
			for(int i = 3;i<n;i++)
			{
				ans+=(((a[i]%P)*(b[i-1]%P))%P*(suf[i+1])%P)%P;
				ans%=P;
				b[i] = ((b[i-1]%P)+((pre[i-1]%P)*(a[i]%P))%P)%P;
				b[i]%=P;
			}
     
			cout<<(ans+P)%P<<"\n";
		}
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	t = 1;
	while (t--) {
		ac();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 79ms
memory: 12680kb

input:

100000
36967178 752077122 899978907 521018044 925360418 267380970 199698530 677842622 395705049 713493724 626147704 827554719 734174727 628149163 731456688 735932512 165335261 961529158 144189583 974116519 739012212 142215106 992295003 210685693 625600330 670647812 636190924 763436680 493995372 4735...

output:

882006095
177429836
87725897
642334982
624917696
585352228
463977870
390469837
85301726
600648670

result:

ok 10 numbers