日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

XXXXX CodeForces - 1364A(思维)

發布時間:2023/12/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XXXXX CodeForces - 1364A(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Ehab loves number theory, but for some reason he hates the number x. Given an array a, find the length of its longest subarray such that the sum of its elements isn’t divisible by x, or determine that such subarray doesn’t exist.

An array a is a subarray of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input
The first line contains an integer t (1≤t≤5) — the number of test cases you need to solve. The description of the test cases follows.

The first line of each test case contains 2 integers n and x (1≤n≤105, 1≤x≤104) — the number of elements in the array a and the number that Ehab hates.

The second line contains n space-separated integers a1, a2, …, an (0≤ai≤104) — the elements of the array a.

Output
For each testcase, print the length of the longest subarray whose sum isn’t divisible by x. If there’s no such subarray, print ?1.

Example
Input
3
3 3
1 2 3
3 4
1 2 3
2 2
0 6
Output
2
3
-1
Note
In the first test case, the subarray [2,3] has sum of elements 5, which isn’t divisible by 3.

In the second test case, the sum of elements of the whole array is 6, which isn’t divisible by 4.

In the third test case, all subarrays have an even sum, so the answer is ?1.

思路:一開始想復雜了,我們比較一下從左邊刪除數字和從右邊刪除數字,最終剩下的長度,選取最大的那個就行了。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=1e5+100; int a[maxx]; int sum[maxx]; int n,x;int main() {int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&x);memset(sum,0,sizeof(sum));for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i];if(sum[n]%x) cout<<n<<endl;else{int ans=-1;for(int i=1;i<=n;i++){if((sum[n]-sum[i])%x){ans=max(ans,n-i);break;}}for(int i=n;i>=1;i--){if(sum[i]%x){ans=max(ans,i);break;}}cout<<ans<<endl;}}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的XXXXX CodeForces - 1364A(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 成年人免费av | 一区二区三区精品免费视频 | 久久av秘一区二区三区 | 69成人网 | 天堂资源中文在线 | 性xxxx欧美老肥妇牲乱 | www.99av| 麻豆91av| 成人福利视频在线观看 | 无人在线观看高清视频 | 懂色av蜜臀av粉嫩av分享吧最新章节 | 强乱中文字幕 | 中日韩在线观看 | 暖暖av| 日本一区二区免费在线观看 | 深夜视频在线免费观看 | 97香蕉| 德国性经典xxxx性hd | a√天堂在线 | 亚洲一区二区动漫 | av剧情在线 | 91精品黄色 | 精品伦理一区二区 | 美女视频网址 | 看国产黄色片 | 美女露胸软件 | 懂色av中文一区二区三区天美 | www.夜夜 | 一区二区三区午夜 | 午夜视频免费在线 | a视频在线看| 伊人一二三 | 狠狠做深爱婷婷综合一区 | 欧美性在线观看 | 夜夜春很很躁夜夜躁 | 自拍在线视频 | 污污网站在线 | 色婷婷激情网 | 亚洲午夜精品一区 | 中文字幕av影视 | 国产九九九九九 | 日本黄色视屏 | 午夜免费小视频 | 欧美三级韩国三级日本三斤 | 日韩少妇视频 | 色www亚洲国产张柏芝 | 在线免费观看欧美大片 | 天堂在线精品 | 成人av免费播放 | 国产成人激情 | 国产九九在线 | 在线黄色观看 | 精品亚洲天堂 | 99久久久久成人国产免费 | 91麻豆网站 | 欧美裸体女人 | av污| 九九九九九伊人 | 黄色片的网站 | 国产污视频网站 | 日本爱爱免费视频 | 嫩草嫩草嫩草嫩草嫩草 | 91福利区| 夜间福利在线观看 | 久久精品人人 | 亚洲 欧美 日韩 在线 | 欧美一级片一区 | 伊人色综合久久久 | 米奇av | 优优色综合 | www.插插| 国产wwwxxx| 特黄一区二区 | 亚洲第一成年网 | 亚洲性视频 | 亚洲精品高清无码视频 | 国产超碰人人爽人人做人人爱 | 亚洲区一区二区三区 | 免费一级欧美 | 国产精品免费一区二区三区四区 | 国产精品无码电影 | 毛片基地在线观看 | 日韩av电影网址 | 国产sm调教视频 | 国产精品乱码 | 一区精品在线 | 天天干天天插天天射 | 制服师生在线 | 精品一区二区欧美 | 美女xx网站 | 亚洲系列 | 人人妻人人澡人人爽欧美一区双 | 日韩精品一区二区三区视频在线观看 | 亚洲视频中文字幕 | 成人午夜免费视频 | 国产电影免费观看高清完整版视频 | 亚洲精品成人a | av在线免费网址 | 亚洲国产av一区二区 |