不会吧
by WilliamFranklin @ 2022-04-14 19:17:54
@[WhyCodePo](/user/316212) java用C语言的代码交当然过不了
by Jason12 @ 2022-04-14 19:19:43
理论上java是可以的吧,,见过用java过的 你要不看看有没有小的智障错误
by Mercury1004 @ 2022-04-14 19:20:15
java用C语言的代码交当然过不了
C语言用java的代码交当然过不了
by ArcherHavetoLearnWhk @ 2022-04-14 19:20:22
有没有一种可能,就是C++和java的语法不一样
by Caviar_X @ 2022-04-14 19:46:38
楼上的似乎理解错楼主的意思了。。。。。
楼主的实际意思是java慢,会tle成70分
```java
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class Main {
static int[] arr;
static int n,m;
static int[] dist;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
n = sc.nextInt();m = sc.nextInt();
arr = new int[n+2];
dist = new int[n];
for (int i = 0; i < n; i++) {
dist[i] = sc.nextInt();
update(i+1,dist[i]);
}
for (int i = 0; i < m; i++) {
int type = sc.nextInt(),k = sc.nextInt(),v = sc.nextInt();
if(type==1)
update(k,v);
else{
int res = getPreAdd(v)-getPreAdd(k-1);
bw.write(Integer.toString(res));
bw.newLine();
}
}
bw.flush();
}
private static int getPreAdd(int k) {
int add1 = 0;
while (k>0){
add1+=arr[k];
k-=Integer.lowestOneBit(k);
}
return add1;
}
private static void update(int pos, int value) {
while (pos<n+1){
arr[pos]+=value;
pos+=Integer.lowestOneBit(pos);
}
}
}
```
by StillEmpty @ 2022-04-14 19:54:30
@[WhyCodePo](/user/316212) 我认真回答:知名竞赛网站codeforces要求所有出题者自己写的java代码能通过。但是洛谷似乎没这个要求,而且本题就有一点卡算法常数因子的,所以会无法通过。
java不太适合信息竞赛
by StillEmpty @ 2022-04-14 19:59:49
洛谷不会为其他比较慢的语言加大时限和空间限制。
有的题目可能是Java绝对无法通过的,因为Java不是编译语言,运行速度较慢,而且读入数据的常数也很大。建议去上其他OJ写Java。
不过本题是有Java8通过的提交的,只能楼主自己优化了(比如加个快读什么的)。
by Terrible @ 2022-04-14 20:17:44
java试了N次过不了,用了快速输入输出也一样,始终70 分
------------
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintStream out = new PrintStream(System.out);
public static void main(String[] args) throws IOException {
String s[] = in.readLine().split("\\s+");
int n = Integer.valueOf(s[0]);
int m = Integer.valueOf(s[1]);
s = in.readLine().split("\\s+");
int nums[] = new int[n+1];
int c[] = new int[nums.length];
for(int i = 1; i <= n; i ++){
nums[i] = Integer.valueOf(s[i-1]);
}
init(c, nums);
for(int i = 0 ; i < m; i ++){
s = in.readLine().split("\\s+");
int opr = Integer.valueOf(s[0]);
int x = Integer.valueOf(s[1]);
int y = Integer.valueOf(s[2]);
if(opr == 1){
add(c, x, y);
}
else {
out.println(count(c, y) - count(c, x-1));
}
}
}
public static void init(int c[],int nums[]){
for(int i = 1; i < nums.length; i ++)
add(c,i,nums[i]);
}
public static void add(int c[],int index,int num){
while(index < c.length){
c[index] += num;
index += lowbit(index);
}
}
public static int count(int c[],int index){
if(index == 0) return 0;
return c[index] + count(c, index - lowbit(index));
}
public static int lowbit(int num){
return num & -num;
}
}
```
by t860421 @ 2023-03-01 18:28:51